#K40902. Smallest Subarray with Sum Greater than K

    ID: 26745 Type: Default 1000ms 256MiB

Smallest Subarray with Sum Greater than K

Smallest Subarray with Sum Greater than K

Given an array of n integers and an integer k, find the length of the smallest contiguous subarray whose sum is greater than k. In other words, find the minimum length L such that there exist indices i and j with 1 ≤ i ≤ j ≤ n satisfying

[ \sum_{m=i}^{j}A_m > k ]

If no such subarray exists, output -1.

Note: A subarray is a contiguous segment of the array.

inputFormat

The input is read from standard input (stdin). The first line contains two space-separated integers n (the number of elements) and k. The second line contains n space-separated integers representing the array elements.

outputFormat

Output a single integer to standard output (stdout) representing the length of the smallest subarray whose sum is greater than k. If no such subarray exists, output -1.## sample

6 51
1 4 45 6 0 19
3