Codeforces и Polygon могут быть недоступны в период с 6 декабря, 22:00 (МСК) по 7 декабря, 00:00 (МСК) в связи с проведением технических работ. ×

Блог пользователя Jashwanth27

Автор Jashwanth27, история, 7 месяцев назад, По-английски

A family is about to break their piggy bank to use the money for different purposes. The piggy bank here represents an array (arr[]) consisting of N coins. The family has to split the coins of piggy bank into smaller stack (sub-array) of coins such that the sum of the difference between the maximum value and the minimum value of the coins for all the stacks (sub-arrays) is maximum. Note: Each value of the array can be used only once that is only in one subarray.

5 8 1 7 9 2

Ans = 14 -> (8-1) + (9-2) [8,1] max — 8, min = 1 [7 9 2] max = 9 min = 2

Полный текст и комментарии »

  • Проголосовать: нравится
  • -3
  • Проголосовать: не нравится