Problems > Shortest Sufficient Stretch

Shortest Sufficient Stretch

Difficulty: 1500 3000 ms 128 MB

sliding-window two-pointers

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

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.