A Two-Pointers Problem

View as PDF

Submit solution

Points: 7 (partial)
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\ (0 \le a_i \le 10^9).

Output Specification

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

Subtasks

Subtask 1 [10%]

N \le 100

Subtask 2 [90%]

No further constraints.

Sample Input

6 3
1 0 2 0 1 2

Sample Output

2

Comments

There are no comments at the moment.