TOO EASY Cookie Run
InterviewTime limit2sMemory limit1024 MB
Find the smallest X added to every stage so that at least K contiguous sections have a sum of at least M.
- Level
Medium6 of 10
- Topics
- Binary search, Two pointers, Prefix sum
- Solved
- No attempts yet
Problem
Cookie Run is a popular game in which a cookie character runs through a map of N stages to score points.

Soo Young, the map designer for Cookie Run, was preparing a new map patch for Children's Day. After she finished building an attractive map and testing it for the last time the day before the patch, she realized the map was designed to be too easy.
The map follows these rules.
- Each stage has a difficulty level . The higher the difficulty, the harder the stage is to pass.
- If the sum of consecutive stages' difficulty levels is at least , the section is called an interesting section. That is, if , the section is an interesting section.
- The map must have at least interesting sections.
In other words, let be the number of pairs with and . Then must hold.
Soo Young requested help from participants of the KAIST RUN Spring Contest. All she can do is add difficulty to all stages at once to make the map harder. Find the smallest non-negative integer that satisfies these conditions.
Input
The first line contains three space-separated integers , , and .
The second line contains space-separated integers .
Output
Print a single non-negative integer, the smallest that satisfies the conditions.
You can assume that at least one non-negative integer exists that satisfies the given conditions.