#K47777. Shortest Subarray with Sum at Least K
Shortest Subarray with Sum at Least K
Shortest Subarray with Sum at Least K
Given an array of integers, find the length of the shortest contiguous subarray whose sum is at least \(k\).
Formally, given an array \(arr\) and an integer \(k\), determine the minimum length \(L\) such that there exists an index \(i\) with
\(\sum_{j=i}^{i+L-1} arr[j] \ge k\)
If no such subarray exists, output -1.
inputFormat
The first line contains two integers \(n\) and \(k\), where \(n\) is the number of elements in the array and \(k\) is the target sum.
The second line contains \(n\) space-separated integers representing the array elements.
outputFormat
Output a single integer representing the length of the shortest contiguous subarray whose sum is at least \(k\). If no such subarray exists, output -1.
## sample10 15
1 2 3 4 5 6 7 8 9 10
2