Suffering
Josh does not like research. He models the n FIT2083 classes of the semester as an array, where ai is the number of Depression Points he gains from attending the ith class.
If the total number of Depression Points from a consecutive block of classes becomes strictly
greater than k, Josh will die. Determine the smallest number of consecutive classes he can
attend and die as a result. If no such block exists, output -1.
Input
The first line contains two integers n and k.
The second line contains n positive integers a1,a2,…,an.
Output
Print a single integer: the minimum length of a contiguous subarray whose sum is strictly greater
than k. If no such subarray exists, print -1.
Constraints
- 1≤n≤105
- 1≤ai≤103
- 1≤k≤109
Example 1
5 11
5 10 1 4 5
2
Explanation
The shortest valid subarray is [5,10], whose sum is 15>11.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.