#CCBCHHAI0000023. Số dương đạt ngưỡng (Positive Contributions to a Target)
Số dương đạt ngưỡng (Positive Contributions to a Target)
Positive Contributions to a Target
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive target and a stream of positive integer contributions, start with cumulative total zero and receive contributions in their given order. Find the minimum number of initial contributions whose sum is at least . Stop immediately upon reaching the target.
Input
The first integer is the target . It is followed by positive contributions, separated by whitespace. The target is first reached after reading the final contribution; no additional value follows.
Output
Print one integer: the smallest number of contributions needed to reach or exceed .
Subtasks
- Subtask 1 (20%): ; at most contributions, each in .
- Subtask 2 (30%): ; at most contributions, each in .
- Subtask 3 (50%): ; at most contributions, each in .
Examples
Example 1
Input
12
3 4 5
Output
3
Explanation
Totals after contributions are 3, 7 and 12. The target 12 is first reached at contribution three.
Example 2
Input
5
9
Output
1
Explanation
The first contribution 9 already exceeds 5, so exactly one contribution is needed.