t it holds load[t] elements, so its size at that moment must be at least load[t]. The waste at moment t is the buffer size minus load[t], and the total waste is the sum over all moments.
The starting size is yours to pick and does not count as a resize. After that you may change the size (to any value) at most resizes times.
Return the smallest possible total waste.load=[4, 8, 6, 2], resizes=1 → 6
Keep size 8 for the first three moments, then shrink to 2: the waste is (8 − 4) + 0 + (8 − 6) + 0 = 6.
load=[7, 3, 9], resizes=0 → 8
No resizing is allowed, so the size is 9 from the start: the waste is 2 + 6 + 0 = 8.
load=[5, 5, 5], resizes=2 → 0
Size 5 fits the whole time, nothing is wasted.
load=[4, 8, 6, 2], resizes=1
6
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.