#CCBCHBON0000015. Dừng tại tổng đạt ngưỡng (First Prefix Reaching a Threshold)
Dừng tại tổng đạt ngưỡng (First Prefix Reaching a Threshold)
First Prefix Reaching a Threshold
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers and a positive threshold , find the smallest 1-based index whose prefix sum is at least . Print -1 if the threshold is never reached. The order of input matters.
Input
The first two integers are , followed by exactly nonnegative integers. , , .
Output
Print the first 1-based position whose prefix sum is at least , or -1.
Subtasks
-
Subtask 1 (20%): ; threshold/budget up to ; values from to .
-
Subtask 2 (30%): ; threshold/budget up to ; values from to .
-
Subtask 3 (50%): ; threshold/budget up to ; values from to .
Examples
Example 1
Input:
4 8
3 5 1 2
Output:
2
Explanation:
Threshold 8; prefix sums by index: 1→3, 2→8. The answer is 2.
Example 2
Input:
3 20
3 5 1
Output:
-1
Explanation:
Threshold 20; prefix sums by index: 1→3, 2→8, 3→9. The answer is -1.