Problem 07C. Shortest Subarray with Sum at Least K ≡

Author:Pavel Mesenev   Time limit:2 sec
Input file:Standard input   Memory limit:256 Mb
Output file:Standard output  

Statement

You are given an array a0, a1, …, an − 1 of integers (may include negatives) and an integer k. Find the length of the shortest non-empty contiguous subarray whose sum is  ≥ k, or report  − 1 if no such subarray exists.

Input format

The first line contains two integers n and k. The second line contains n space-separated integers a0… an − 1.

Output format

Print one integer: the shortest length, or  − 1.

Constraints

1 ≤ n ≤ 2 ⋅ 105

 − 1000 ≤ ai ≤ 1000

 − 109 ≤ k ≤ 109

Sample tests

No. Standard input Standard output
1
1 1
1
1
2
2 4
1 2
-1
3
3 3
2 -1 2
3

0.040s 0.010s 16