Lazy to Win
InterviewTime limit1sMemory limit1024 MB
Given the point values of n problems, find the fewest consecutive problems, skipping at most one, needed to reach at least half of the total score.
- Level
Medium4 of 10
- Topics
- Sliding window, Prefix sum, Array
- Solved
- No attempts yet
Problem
Alexey is probably the smartest and at the same time the laziest person in the world. Today he is participating in the Olympiad.
At the Olympiad, participants are given problems. A participant receives points for a correct solution of the -th problem. No points are given for an incorrect solution. Participants who receive at least half of the total points are awarded a winner's diploma. For example, if there are three problems worth , , and points, a participant needs four points to earn the diploma.
Alexey came to the Olympiad to get a winner's diploma. He can correctly solve any problem. He is also very lazy and wants to solve as few problems as possible.
Alexey chooses his problems lazily too. He picks a problem number , then solves problems until he has enough points for a diploma. He allows himself to skip at most one problem, if skipping it lets him solve fewer problems in the end.
Determine the minimum number of problems Alexey needs to solve with this strategy to get the winner's diploma.
Input
On the first line there is one integer , the number of problems ().
On the second line there are integers , the cost of each problem in points ().
Output
On the first line, output a single integer: the minimum number of problems Alexey needs to solve with his strategy to get the winner's diploma.
Hint
In the first example, participants need at least four points to get the winner's diploma. Alexey can start solving the third problem, then skip the fourth problem and get four points by solving two tasks.
In the second example, it is enough to solve only the second problem to receive three points.