Shortest Sufficient Stretch
Values are positive. Find the length of the shortest contiguous stretch whose sum is at least K, or −1 if no stretch reaches K.
Input: the first line has N and K; the second line has N positive integers.
Output: the minimum length, or −1.
Constraints:
- 1 ≤ N ≤ 105
- 1 ≤ ai ≤ 104
- 1 ≤ K ≤ 109
Sample Tests
Input 1
6 7 2 3 1 2 4 3
Output 1
2
Input 2
3 100 1 2 3
Output 2
-1
Discussion (opens after you solve — no spoilers before)
No comments yet.