#CCBCHMOT0000029. Vượt ngưỡng Z (Exceeding Z)
Vượt ngưỡng Z (Exceeding Z)
Exceeding Z
Source: beecrowd
Version: Phuoc Hung OJ Extended
Problem Statement
Read integer X, then successive candidates for Z. Discard candidates Z <= X and select the first Z > X. Add consecutive integers X, X+1, X+2, ... until the sum is strictly greater than Z. Print the minimum number of terms.
Input
The first integer is X, followed by candidates for Z until the first one greater than X, inclusive.
Output
Print the smallest count of consecutive terms whose sum exceeds Z.
Subtasks
- Subtask 1 (20%): 1<=X<=10, each candidate Z in [-100,100], at most 5 candidates.
- Subtask 2 (30%): -20<=X<=50, candidates in [-10000,10000], at most 20.
- Subtask 3 (50%): -1000<=X<=1000, candidates in [-1000000,1000000], at most 100.
Examples
Example 1
Input
3
1
20
Output
5
Explanation
Ignore Z=1. Partial sums for 3,4,5,6,7 are 3,7,12,18,25; the fifth first exceeds 20.
Example 2
Input
21
21
15
30
Output
2
Explanation
Candidates 21 and 15 are invalid. 21 alone does not exceed 30, while 21+22=43 does.