#CCBCHBON0000018. Dừng khi vượt hạn mức (Stop Before Exceeding the Budget)
Dừng khi vượt hạn mức (Stop Before Exceeding the Budget)
Stop Before Exceeding the Budget
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given budget and nonnegative expenses in order, accept the longest initial prefix whose running total never exceeds . Stop before the first expense that would exceed ; do not skip it to examine later expenses. Equality with is allowed. Print the number accepted.
Input
Read , then exactly integer expenses . , , .
Output
Print the number of expenses accepted before stopping.
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 10
3 5 4 1
Output:
2
Explanation:
Budget 10; accept the initial expenses until the first one that would exceed it. Accepted count: 2.
Example 2
Input:
3 8
3 5 0
Output:
3
Explanation:
Budget 8; accept the initial expenses until the first one that would exceed it. Accepted count: 3.