#P12372. Zeroing Out Sequence
Zeroing Out Sequence
Zeroing Out Sequence
Given a sequence of integers of length \(N\): \(A_1, A_2, \cdots, A_N\). Blue wants to reduce every number in the sequence to zero by performing a series of operations. In each operation, Blue can choose one of the following:
- Pick any positive integer and subtract \(1\) from it.
- Pick \(K\) consecutive positive integers and subtract \(1\) from each of them.
Determine the minimum number of operations required to turn the entire sequence into zeros.
inputFormat
The first line contains two integers \(N\) and \(K\) (\(1 \leq N \leq 10^5\), \(1 \leq K \leq N\)).
The second line contains \(N\) integers: \(A_1, A_2, \ldots, A_N\) where \(0 \leq A_i \leq 10^9\).
outputFormat
Output a single integer representing the minimum number of operations required to reduce the entire sequence to zero.
sample
5 2
3 2 1 4 2
7