INTEG - Editorial

Explanation to the 3rd STEP : INTEG @user-rsaha solution to this problem - general - CodeChef Discuss:slight_smile:

For this test case -4, -1, 0, -2, -3, -2 and X = 3, shouldn’t the ans be 10??

let’s sort the array in descending order

0 -1 -2 -2 -3 -4

Apply coins

1 0 -1 -1 -2 -3 - 3 coins

2 1 0 0 -1 -2 - 3 coins

3 2 1 1 0 -1 - 3 coins

3 2 1 1 0 0 - 1 coin

Total number of coins are 10 which is optimal. Please correct me if my understanding is wrong.

Yes you’re wrong. The optimal number is 9, since you can increment two elements for 2 in the third step.

Don’get confused by the example in the editorial. It’s purpose is to demonstrate that always using operation 2 doesn’t yield an optimal result