Divide array in three parts

Правка en3, от maxifier, 2022-01-17 18:34:02

I was solving this problem. While solving this problem i encountered a sub-problem.

We have an array of n length and we want to divide it into three parts such that after dividing the array sum of individual arrays should be as close to the power of 2 greater than or equal to the sum as possible.

More formally, let say sum1, sum2, sum3 are the sums of subarrays. Our answer is minimum possible value of (p1 — sum1) + (p2 — sum2) + (p3 — sum3). Here, p1, p2, p3 are the powers of two.

For Example : let say our array is [4, 1, 1, 2, 3, 1]

-> If we divide this array as [4, 1], [1, 2], [3, 1] then our answer is (8 — 5) + (4 — 3) + (4 — 4) = 0.

-> If we divide this array as [4], [1, 1, 2], [3, 1] the our answer is (4 — 4) + (4 — 4) + (4 — 4) = 0 which is optimal in this case.

Constraints: 1<= n <= 1e5, 1 <= ai <=n

I would be grateful if you help me to solve this Problem.

Теги need help, arrays, codeforces, educational rounds

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский maxifier 2022-01-17 18:34:02 42 Tiny change: ' case.\n\nI woul' -> ' case.\n\nConstraints: 1<=n<=1e5, 1<=ai<=n\n\nI woul'
en2 Английский maxifier 2022-01-17 17:25:12 20
en1 Английский maxifier 2022-01-17 17:12:32 1013 Initial revision (published)