Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

The Smallest Window I

For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0.

Constraints

$1 \leq N \leq 10^5$

$1 \leq S \leq 10^9$

$1 \leq a_i \leq 10^4$

Input

The input is given in the following format.

$N$ $S$

$a_1$ $a_2$ ... $a_N$

Output

Print the smallest sub-array size in a line.

Sample Input 1

6 4
1 2 1 2 3 2

Sample Output 1

2

Sample Input 2

6 6
1 2 1 2 3 2

Sample Output 2

3

Sample Input 3

3 7
1 2 3

Sample Output 3

0

Solution in C++14 (judge verdict: Accepted)

#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(int32 i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int32 i = (b) - 1; i >= (a); --i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define ALL(x) (x).begin(),(x).end()
#define C(x) cout << #x << ":" << x << endl
#define scanf scanf_s

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;
inline uint32 MIN(uint32 a, uint32 b){
	return a > b ? b : a;
}

int main() {
	uint32 n;
	uint32 s;
	cin >> n >> s;
	vector<uint32> a(n + 1);
	a[n] = 0;
	rep(i, 0, n)
		cin >> a[i];
	uint32 ans = n + 1;
	uint32 now = 0;
	uint32 l = 0, r = 0;
	while (r <= n){
		if (now < s){
			now += a[r++];
		}
		else{
			ans = MIN(ans, r-l);
			now -= a[l++];
		}
	}
	if (ans == n + 1) ans = 0;
	printf("%u\n", ans);
	return 0;
}