A Two-Pointers Problem 2

View as PDF

Submit solution

Points: 12
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Given an array a of N integers, find the shortest length subarray that has a sum greater than or equal to M.

Input Specification

The first line will contain 2 integers, N, M\ (1 \le N \le 10^5, 1 \le M \le 10^9).

The second line will contain N integers a_1, a_2, \ldots, a_N\ (|a_i| \le 10^7).

Output Specification

Output the shortest length subarray that has a sum greater than or equal to M. If there is no subarray, print -1.

Sample Input

6 3
2 0 -1 2 -1 2

Sample Output

3

Comments

There are no comments at the moment.