Comments
+3

This line:if(arr[i-1]>=arr[i]) c+=min(k,arr[i])+abs(arr[i]-arr[i-1]);

The conditional is unnecesary, because you can add blocks to the bag while arr[i-1]>arr[i]-k. With that, the sum changes too, the absolute value will generate wrong answer. You should change that line to: c+=min(k,arr[i])+arr[i-1]-arr[i];

When you do the sum m+= k-abs(h2-h1) you are forgetting that the number of blocks of height h1 could be less than k-abs(h2-h1), so when you do that sum, the remaining number of blocks of that pile become negative, and that's impossible. So, the sum is m+=min(h1, k-abs(h2-h1)), and with that the number of blocks will never be negative.

+3

edited

0

You mean s+(t-s)/2

On top34051 → Codeforces Round #542, 8 years ago
+1

How much time does it has to pass after the contest is finished to be able to submit a solution of one of the problems? I want to submit my codes for the D1 and D2 problems.