Leaf Cleanup
InterviewTime limit1sMemory limit1024 MB
Given n pile sizes, choose a range of k consecutive integers within 1 to c that minimizes the total size of the piles falling inside it.
- Level
Medium5 of 10
- Topics
- Sorting, Prefix sum, Binary search
- Solved
- No attempts yet
Statement
While solving problem C, you may have learned about the results of cleaning Evstigraf's yard. This problem focuses on the process instead of the result.
During the cleaning, one of the main challenges was gathering the leaves that had fallen on the ground into piles that would satisfy Evstigraf. In total, piles were collected, and the -th pile contains exactly leaves. The piles were then shown to Evstigraf.
Evstigraf does not want to spend time checking every pile, so he evaluates the work with this rule:
- First, he asks you to name a contiguous range of exactly integers, that is, some with .
- Then he computes the sum of the sizes of the piles that fall into this range: .
The lower the value of , the better the cleaning. Help the cleaners choose and so that is as small as possible. and cannot be negative or too large: must hold for the given .
Input
The first line contains three integers , , and separated by spaces: the number of piles, the upper bound on the chosen range, and the length of the range (; ).
The second line contains integers , the sizes of the piles ().
Output
Print one number: the minimum possible value of the sum described above.