#CCBCHHAI0000029. Tích lũy đến mục tiêu (Accumulate Until Target)
Tích lũy đến mục tiêu (Accumulate Until Target)
Accumulate Until Target
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer target and nonnegative integer contributions, start with total zero and receive contributions in order. Find the fewest reads required for the total to reach or exceed . A zero contribution still counts as a read but does not increase the total.
Input
The first integer is ; nonnegative contributions follow. The final contribution is the first to bring the running total to or above , and no additional input follows.
Output
Print the minimum number of contributions read to reach the target.
Subtasks
- Subtask 1 (20%): , at most contributions in .
- Subtask 2 (30%): , at most contributions in .
- Subtask 3 (50%): , at most contributions in .
Examples
Example 1
Input
10
0 4 0 6
Output
4
Explanation
Running totals are 0, 4, 4, 10. Zeros count as reads. The target is first reached at read four.
Example 2
Input
3
3
Output
1
Explanation
The first contribution reaches the target exactly, so output one.