Shortest Stretch Reaching S

easy sliding-window two-pointers arrays 1000 ms · 256 MB

Shortest Stretch Reaching S

You are given an array of n positive integers a_1, a_2, ..., a_n and a target S.

A stretch is a contiguous subarray a_l, a_{l+1}, ..., a_r with 1 ≤ l ≤ r ≤ n; its length is r − l + 1. Find the length of the shortest stretch whose sum is at least S.

If no stretch reaches S (that is, even the whole array sums to less than S), the answer is 0.

Input

The first line contains two integers n and S (1 ≤ n ≤ 10^6, 1 ≤ S ≤ 10^15).

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ 10^9).

Output

Print a single integer: the minimum length of a contiguous subarray with sum at least S, or 0 if there is none.

Notes

In the first example, the stretch 4 3 has sum 7 ≥ 7 and length 2, and no single element reaches 7.

In the second example, the whole array sums to 10 < 11, so the answer is 0.

Sums can exceed 2^31; use 64-bit integers.

Example 1

Input

6 7
2 3 1 2 4 3

Output

2

Example 2

Input

4 11
1 2 3 4

Output

0

Hints · reveal one at a time if you're stuck

Hint 1

All the values are positive. What does that say about how a window's sum changes when you extend it on the right or shrink it on the left? Does the best starting point ever need to move backwards as the window's right end moves forward?

Hint 2

Keep a window whose two ends only move forward: extend the right end one element at a time, and shrink from the left while the window still reaches S. Use 64-bit sums, and print 0 if no window ever reaches S.

report an issue Prefer your own editor? sooks prep 31 (CLI)
Sign in to run code

Run your code on the examples, or submit it against every test.