Shortest Subsequence With Sum at Least X
Time limit3sMemory limit256 MB
Find the length of the shortest contiguous subarray whose sum is at least X, or report -1 when none exists.
- Level
Medium7 of 10
- Topics
- Prefix sum, Queue
- Solved
- No attempts yet
Problem
You are given an integer sequence of length and an integer .
Consider the subsequences of consecutive elements () whose elements sum to or more. Write a program that finds the length of the shortest such subsequence. A subsequence holds at least one element.
Input
The first line contains the number of test cases .
The first line of each test case contains () and (). The second line contains the elements of the sequence, separated by spaces. Each element is an integer between and .
Output
For each test case, print on one line the shortest length among the subsequences of consecutive elements whose sum is or more. If there is no such subsequence, print .