#CCBOTPBA0000051. Lần đầu vượt ngân sách (First Budget Exceedance)
Lần đầu vượt ngân sách (First Budget Exceedance)
First Budget Exceedance
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
A person has a budget of and records expenses in chronological order. The -th expense costs . The cumulative cost after expense is . Find the first 1-based position such that . If no expense makes the cumulative cost exceed the budget, print . When , there are no expenses.
Input
The first line contains two integers and : the number of expenses and the budget. If , the following input contains non-negative integers in chronological order, separated by whitespace and possibly spread across multiple lines. If , no follows.
Output
Print one integer: the smallest position with , or if none exists.
Subtasks
- Subtask 1 (20%): .
- Subtask 2 (30%): .
- Subtask 3 (50%): .
Examples
Example 1
Input:
4 10
3 2 6 1
Output:
3
Explanation: The first three cumulative costs are , , and . Since and the earlier totals are not above , the first position is .
Example 2
Input:
3 10
4 6 0
Output:
-1
Explanation: The cumulative costs are , , and . Equality with the budget is not an exceedance. No valid position exists.
Example 3
Input:
0 0
Output:
-1
Explanation: There are no expenses, so no position can exceed the budget.