Problem:
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

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;

int main(){
    int N, S;
    cin >> N >> S;
    vector<int> a(N);
    for(auto& i : a) cin >> i;
    int ans = 1000000000;
    for(int s = 0, t = 0, sum = 0; t < N;){
        sum += a[t];
        if(sum < N) t++;
        else{
            while(s < t && sum >= N) sum -= a[s++];
            ans = min(ans, t - s + 2);
        }
    }
    cout << ans << endl;
    return 0;
}
accuracy: 0.02
time_ms: 670
memory_kb: 3456
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

int smallSubArray(int a[],int n, int s)
{
	int ans=INT_MAX,start=0,sum=0;
	for(int end=0;end<n; end++)
	{
		sum+=a[end];
		while(sum-a[start]>=s) 
		{
			sum-=a[start];
			start++;
		}
		if(sum>=s) 
		  ans=min(ans,end-start+1);
	}
	if(ans==INT_MAX)
	  return 0;
	return ans; 
}

int main() {
	// your code goes here
	int n, s; 
	cin>>n>>s; 
	int a[n];
	for(int i=0;i<n;i++)
	  cin>>a[i];
	cout<<smallSubArray(a,n,s)<<endl;;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3824
final_rank: 12

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m; cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    
    queue<int> q;
    int sum=0,i,minsize=n,flag=0;
    
    for(i=0;i<n;i++)
    {
        q.push(a[i]);
        sum+=a[i];
        while(sum>=m)
        {
            flag=1;
            if(q.size()<=minsize)
            {
                minsize=q.size();
            }
            sum=sum-q.front();
            q.pop();
        }
    }
    
    if(flag==1)
    {
        cout<<minsize;
    }
    else
    {
        cout<<0;
    }

    cout<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4148
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m; cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    queue<int> q;
    int sum=0,i,minsize=INT_MAX,flag=0;
    for(i=0;i<n;i++)
    {
        q.push(a[i]);
        sum+=a[i];
        while(sum>=m)
        {
            flag=1;
            if(q.size()<=minsize)
            {
                minsize=q.size();
            }
            sum=sum-q.front();
            q.pop();
        }
    }
    if(flag==1)
    {
        cout<<minsize;
    }
    else
    {
        cout<<0;
    }

    cout<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 4244
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
template<class T,T(*op)(T,T),T(*e)()>
struct fenwick{
	int n;vector<T>d;
	fenwick(int n):n(n),d(n,e()){}
	template<class U>fenwick(vector<U>a):fenwick(a.size()){
		for(int i=0;i<n;i++){
			d[i]=op(d[i],a[i]);
			int j=i|i+1;
			if(j<n)d[j]=op(d[j],d[i]);
		}
	}
	void apply(int i,T x){
		assert(0<=i);
		while(i<n)d[i]=op(d[i],x),i|=i+1;
	}
	T operator[](int i){
		assert(i<n);
		T y{};while(i>=0)y=op(y,d[i]),i&=i+1,i--;return y;
	}
	template<class F>int max_right(F ok){
		assert(ok(e()));
		T y=e();int i=0,w=1;while(w<=n)w<<=1;
		while(w>>=1)if(i+w<=n&&ok(op(y,d[i+w-1])))y=op(y,d[(i+=w)-1]);
		return i;
	}
};
int op(int x,int y){return x+y;}
int e(){return 0;}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	fenwick<int,op,e>s(a);
	int ans=n+1;
	for(int i=0;i<n;i++){
		int r=s.max_right([&](int x){return x<k+s[i-1];});
		if(r==n)break;
		ans=min(ans,r-i+1);
	}
	if(ans==n+1)ans=0;
	cout<<ans<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4400
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
template<class T,T(*op)(T,T),T(*e)()>
struct fenwick{
	int n;vector<T>d;
	fenwick(int n):n(n),d(n,e()){}
	template<class U>fenwick(vector<U>a):fenwick(a.size()){
		for(int i=0;i<n;i++){
			d[i]=op(d[i],a[i]);
			int j=i|i+1;
			if(j<n)d[j]=op(d[j],d[i]);
		}
	}
	void apply(int i,T x){
		assert(0<=i);
		while(i<n)d[i]=op(d[i],x),i|=i+1;
	}
	T operator[](int i){
		assert(i<n);
		T y{};while(i>=0)y=op(y,d[i]),i&=i+1,i--;return y;
	}
	template<class F>int max_right(F ok){
		T y=e();int i=0,w=1;while(w<=n)w<<=1;
		while(w>>=1)if(i+w<=n&&ok(op(y,d[i+w-1])))y=op(y,d[(i+=w)-1]);
		return i;
	}
};
int op(int x,int y){return x+y;}
int e(){return 0;}
int main(){
	ios::sync_with_stdio(0),cin.tie(0);
	int n,k;
	cin>>n>>k;
	vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	fenwick<int,op,e>s(a);
	int ans=n+1;
	for(int i=0;i<n;i++){
		int r=s.max_right([&](int x){return x<k+s[i-1];});
		if(r==n)break;
		ans=min(ans,r-i+1);
	}
	if(ans==n+1)ans=0;
	cout<<ans<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4400
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
template<class T>
struct fenwick{
	int n;vector<T>d;
	fenwick(int n):n(n),d(n){}
	template<class U>fenwick(vector<U>a):fenwick(a.size()){
		for(int i=0;i<n;i++){d[i]+=a[i];if((i|i+1)<n)d[i|i+1]+=d[i];}
	}
	void add(int i,T x){while(i<n)d[i]+=x,i|=i+1;}
	T operator[](int i){T y{};while(i>=0)y+=d[i],i&=i+1,i--;return y;}
	int lower_bound(T x){
		int i=0,w=1;while(w<=n)w<<=1;
		while(w>>=1)if(i+w<=n&&d[i+w-1]<x)x-=d[(i+=w)-1];
		return i;
	}
};
int main(){
	int n,S;
	cin>>n>>S;
	vector<int>a(n);for(int i=0;i<n;i++)cin>>a[i];
	fenwick<int>s(a);
	int ans=n+1;
	for(int i=0;i<n;i++){
		int r=s.lower_bound(S+s[i-1]);
		if(r==n)break;
		ans=min(ans,r-i+1);
	}
	if(ans==n+1)ans=0;
	cout<<ans<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 4136
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
template<class T>
struct fenwick{
	int n;vector<T>d;
	fenwick(int n):n(n),d(n){}
	void add(int i,T x){while(i<n)d[i]+=x,i|=i+1;}
	T operator[](int i){T y{};while(i>=0)y+=d[i],i&=i+1,i--;return y;}
	int lower_bound(T x){
		int i=0,w=1;while(w<=n)w<<=1;
		while(w>>=1)if(i+w<=n&&d[i+w-1]<x)x-=d[(i+=w)-1];
		return i;
	}
};
int main(){
	int n,S;
	cin>>n>>S;
	fenwick<int>s(n);
	for(int i=0;i<n;i++){
		int a;cin>>a;s.add(i,a);
	}
	int ans=n+1;
	for(int i=0;i<n;i++){
		int r=s.lower_bound(S+s[i-1]);
		if(r==n)break;
		ans=min(ans,r-i+1);
	}
	if(ans==n+1)ans=0;
	cout<<ans<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3596
final_rank: 2

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<deque>
#include<list>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ld EPS = 1e-10;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
const ld PI = acos( -1.0 );

#define SWAP( A, B ) { auto tmp = A; A = B; B = tmp; }

template <typename T>
void print( vector<T> v ){
    if( v.size() == 0 ) return;
    for( int i = 0 ; i < v.size() - 1 ; i++ )
        cout << v[i] << ' ';
    cout << v[v.size()-1] << endl;
}

int smallest_window( ll S, const vector<ll> &number ){

    int left = 0, right = 0, res = number.size() + 1;
    ll sum = 0;

    while( left < number.size() ){
        while( right < number.size() && sum < S )
            sum += number[right++];
        if( sum >= S )
            res = min( res, right - left );
        sum -= number[left++];
    }
    return ( res <= number.size() ? res : 0 );

}

int main(){

    int N;
    ll S, a;
    vector<ll> number;

    cin >> N >> S;
    for( int i = 0 ; i < N ; i++ ){
        cin >> a;
        number.push_back( a );
    }
    cout << smallest_window( S, number ) << endl;

}
accuracy: 1
time_ms: 10
memory_kb: 4132
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
// const ll INF64 = 1LL << 60;
const ll INF64 = ((1LL<<62)-(1LL<<31));  // 10^18より大きく、かつ2倍しても負にならない数
const int INF32 = 0x3FFFFFFF;  // =(2^30)-1 10^9より大きく、かつ2倍しても負にならない数
template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; }
#define YesNo(T) cout << ((T) ? "Yes" : "No") << endl;  // T:bool

// AOJ DSL_3_A
// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/3/DSL_3_A

// 尺取り法の練習問題

int main(void)
{
	int i;
	int N, S; cin >> N >> S;
	vector<int> a(N); for(i = 0; i < N; i++) {cin >> a[i];}

	int l, r;
	r = 0;
	int ans = INF32;
	int sum = 0;
	for(l = 0; l < N; l++)  // [l,r)
	{
		while(r < N && sum < S)  // 条件を満たすまで移動
		{
			sum += a[r];
			r++;
		}
		if(sum >= S)
		{
			chmin(ans, r-l);
		}
		sum -= a[l];
		// lがrを超えることは無い
	}
	if(ans == INF32) ans = 0;
	cout << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3640
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
// const ll INF64 = 1LL << 60;
const ll INF64 = ((1LL<<62)-(1LL<<31));  // 10^18より大きく、かつ2倍しても負にならない数
const int INF32 = 0x3FFFFFFF;  // =(2^30)-1 10^9より大きく、かつ2倍しても負にならない数
template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; }
#define YesNo(T) cout << ((T) ? "Yes" : "No") << endl;  // T:bool

// AOJ DSL_3_A
// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/3/DSL_3_A

/*
 * 
 * 
 */

int main(void)
{
	int i;
	int N, S; cin >> N >> S;
	vector<int> a(N); for(i = 0; i < N; i++) {cin >> a[i];}

	int l, r;
	r = 0;
	int ans = INF32;
	int sum = 0;
	for(l = 0; l < N; l++)  // [l,r)
	{
		while(r < N && sum < S)  // 条件を満たすまで移動
		{
			sum += a[r];
			r++;
		}
		if(sum >= S)
		{
			chmin(ans, r-l);
		}
		sum -= a[l];
	}
	if(ans == INF32) ans = 0;
	cout << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3632
final_rank: 5

code_snippet: #include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <concepts>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numbers>
#include <numeric>
#include <queue>
#include <random>
#include <ranges>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

constexpr int MOD{1'000'000'007};
constexpr int MOD2{998'244'353};
constexpr int INF{1'000'000'000}; //1e9
constexpr int NIL{-1};
constexpr long long LINF{1'000'000'000'000'000'000}; // 1e18
constexpr long double EPS{1E-10L};
using namespace std::literals;
namespace ranges = std::ranges;
namespace views = ranges::views;

template<class T, class S> bool chmax(T &a, const S &b){
    if(a < b){a = b; return true;}
    return false;
}
template<class T, class S> bool chmin(T &a, const S &b){
    if(b < a){a = b; return true;}
    return false;
}
template<class T> bool inside(T x, T lx, T rx){ //semi-open
    return (ranges::clamp(x, lx, rx-1) == x);
}
template<class T> bool inside(T x, T y, T lx, T rx, T ly, T ry){
    return inside(x, lx, rx) && inside(y, ly, ry);
}
template<class T, class S> std::istream &operator>>(std::istream &is, std::pair<T, S> &p){
    return is >> p.first >> p.second;
}
template<class T, class S> std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &p){
    return os << p.first << " " << p.second;
}
template<class T> std::istream &operator>>(std::istream &is, std::vector<T> &v){
    {for(auto &e: v) is >> e;} return is;
}
template<class Container> void print_container(const Container &c, std::string sep = " "s, std::string end = "\n"s){
    for(int i{int(std::size(c))}; auto e: c) std::cout << e << (--i ? sep : end);
}
std::string yesno(bool x){return x ? "Yes"s : "No"s;}



int main(){
    std::cout << [](){
        int N, S, s{}; std::cin >> N >> S;
        std::vector<int> a(N);
        for(int &e: a){
            std::cin >> e; s += e;
        }
        if(s < S) return 0;
        int ans{INF}; s = 0;
        for(int i{0}, j{-1}; i < N; ++i){
            while(j < N-1 && s < S) s += a[++j];
            if(s >= S) chmin(ans, j - i + 1);
            s -= a[i];
        }
        return ans;
    }() << std::endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 7

code_snippet: #include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <concepts>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numbers>
#include <numeric>
#include <queue>
#include <random>
#include <ranges>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

constexpr int MOD{1'000'000'007};
constexpr int MOD2{998'244'353};
constexpr int INF{1'000'000'000}; //1e9
constexpr int NIL{-1};
constexpr long long LINF{1'000'000'000'000'000'000}; // 1e18
constexpr long double EPS{1E-10L};
using namespace std::literals;
namespace ranges = std::ranges;
namespace views = ranges::views;

template<class T, class S> bool chmax(T &a, const S &b){
    if(a < b){a = b; return true;}
    return false;
}
template<class T, class S> bool chmin(T &a, const S &b){
    if(b < a){a = b; return true;}
    return false;
}
template<class T> bool inside(T x, T lx, T rx){ //semi-open
    return (ranges::clamp(x, lx, rx-1) == x);
}
template<class T> bool inside(T x, T y, T lx, T rx, T ly, T ry){
    return inside(x, lx, rx) && inside(y, ly, ry);
}
template<class T, class S> std::istream &operator>>(std::istream &is, std::pair<T, S> &p){
    return is >> p.first >> p.second;
}
template<class T, class S> std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &p){
    return os << p.first << " " << p.second;
}
template<class T> std::istream &operator>>(std::istream &is, std::vector<T> &v){
    {for(auto &e: v) is >> e;} return is;
}
template<class Container> void print_container(const Container &c, std::string sep = " "s, std::string end = "\n"s){
    for(int i{int(std::size(c))}; auto e: c) std::cout << e << (--i ? sep : end);
}
std::string yesno(bool x){return x ? "Yes"s : "No"s;}



int main(){
    std::cout << [](){
        int N, S, s{}; std::cin >> N >> S;
        std::vector<int> a(N);
        for(int &e: a){
            std::cin >> e; s += e;
        }
        if(s < S) return 0;
        int ans{INF}, j{-1}; s = 0;
        for(int i{0}; i < N; ++i){
            while(j < N-1 && s < S) s += a[++j];
            if(s >= S) chmin(ans, j - i + 1);
            s -= a[i];
        }
        return ans;
    }() << std::endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 7

code_snippet: #include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <concepts>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numbers>
#include <numeric>
#include <queue>
#include <random>
#include <ranges>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

constexpr int MOD{1'000'000'007};
constexpr int MOD2{998'244'353};
constexpr int INF{1'000'000'000}; //1e9
constexpr int NIL{-1};
constexpr long long LINF{1'000'000'000'000'000'000}; // 1e18
constexpr long double EPS{1E-10L};
using namespace std::literals;
namespace ranges = std::ranges;
namespace views = ranges::views;

template<class T, class S> bool chmax(T &a, const S &b){
    if(a < b){a = b; return true;}
    return false;
}
template<class T, class S> bool chmin(T &a, const S &b){
    if(b < a){a = b; return true;}
    return false;
}
template<class T> bool inside(T x, T lx, T rx){ //semi-open
    return (ranges::clamp(x, lx, rx-1) == x);
}
template<class T> bool inside(T x, T y, T lx, T rx, T ly, T ry){
    return inside(x, lx, rx) && inside(y, ly, ry);
}
template<class T, class S> std::istream &operator>>(std::istream &is, std::pair<T, S> &p){
    return is >> p.first >> p.second;
}
template<class T, class S> std::ostream &operator<<(std::ostream &os, const std::pair<T, S> &p){
    return os << p.first << " " << p.second;
}
template<class T> std::istream &operator>>(std::istream &is, std::vector<T> &v){
    {for(auto &e: v) is >> e;} return is;
}
template<class Container> void print_container(const Container &c, std::string sep = " "s, std::string end = "\n"s){
    for(int i{int(std::size(c))}; auto e: c) std::cout << e << (--i ? sep : end);
}
std::string yesno(bool x){return x ? "Yes"s : "No"s;}



int main(){
    std::cout << [](){
        int N, S, s{}; std::cin >> N >> S;
        std::vector<int> a(N);
        for(int &e: a){
            std::cin >> e; s += e;
        }
        if(s < S) return 0;
        int ans{INF}, j{-1}; s = 0;
        for(int i{0}; i < N; ++i){
            if(j < i){
                j = i; s = a[i];
            }
            while(j < N-1 && s < S) s += a[++j];
            if(s >= S) chmin(ans, j - i + 1);
            s -= a[i];
        }
        return ans;
    }() << std::endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 7

code_snippet: #include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,s;
  cin>>n>>s;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int ans=n+1;
  for(int l=0,r=0,sum=0;r<=n;){
    if(l>r)r=l,sum=0;
    while(r<n&&sum<s)sum+=a[r++];
    if(sum>=s)if(ans>r-l)ans=r-l;
    sum-=a[l++];
  }
  if(ans==n+1)ans=0;
  cout<<ans<<endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n,s;
    cin>>n>>s;
    vector<int> a(n);
    for(auto &e:a)cin>>e;
    int r=0;
    long sum=0;
    int ans=1<<30;
    for(int l=0;l<n;l++){
        while(r!=n and sum<s){
            sum+=a[r++];
        }
        int val=r-l;
        if(sum>=s and ans>val) ans=val;
        sum-=a[l];
    }
    cout<<(ans!=1<<30?ans:0)<<'\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 7

code_snippet: #include <bits/stdc++.h>

using namespace std;

// long longの省略
typedef long long ll;

// rep(先頭にRで逆からループ、末尾にSで「1～n」となる)
#define rep(i, a, n) for(int i = a; i < n; i++)
#define reps(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = n - 1; i >= a; i--)
#define rreps(i, a, n) for(int i = n; i >= a; i--)

// ソートなどに対象を入れる場合
#define all(x) (x).begin(),(x).end()

// ソートされた配列から重複を削除して詰めなおす
#define UNIQUE(x) x.erase( unique(x.begin(), x.end()), x.end() );

int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int __gcd(int a, int b){
	int c;

	while((c = a % b) != 0){
		a = b;
		b = c;
	}

	return b;
}

// 「number」の「n」ビット目が「1」であるか「0」か
// ビット目の数え方は配列の添え字と同じ
bool __bit(int number, int n){
	if(number & (1 << n))
		return true;

	return false;
}

// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
	if (a < b) {
		a = b;  // aをbで更新
		return true;
	}

	return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
	if (a > b) {
		a = b;  // aをbで更新
	return true;
	}

	return false;
}

ll mod_pow(ll a, ll n, ll mod) {
	ll res = 1;
	// n を 2進数に変換して考える
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main(){
	ll N, S; cin >> N >> S;

	vector<ll> A(N);
	rep(i, 0, N) cin >> A[i];

	vector<ll> psum(N + 1);
	reps(i, 1, N) psum[i] = psum[i - 1] + A[i - 1];

	int ans = INT_MAX, r = 0;
	rep(l, 0, N){
		while(r < N && psum[r + 1] - psum[l] < S)
			r++;

		if(r < N && S <= psum[r + 1] - psum[l])
			chmin(ans, r - l + 1);
	}

	cout << (ans == INT_MAX ? 0 : ans) << endl;

	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 4740
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <climits>

using namespace std;

int smallestSubarrayWithGivenSum(int N, int S, vector<int>& arr) {
    int current_sum = 0;
    int min_length = INT_MAX;
    int start = 0;

    for (int end = 0; end < N; ++end) {
        current_sum += arr[end];

        while (current_sum >= S) {
            min_length = min(min_length, end - start + 1);
            current_sum -= arr[start];
            ++start;
        }
    }

    return (min_length == INT_MAX) ? 0 : min_length;
}

int main() {
    int N, S;
    cin >> N >> S;
    vector<int> arr(N);

    for (int i = 0; i < N; ++i) {
        cin >> arr[i];
    }

    int result = smallestSubarrayWithGivenSum(N, S, arr);
    cout << result << endl;

    return 0;
}
//sonia
accuracy: 1
time_ms: 10
memory_kb: 3608
final_rank: 3

code_snippet: #include <iostream>
#include <vector>
#include <climits>
using namespace std;

int main() {
    int N, S;
    cin >> N >> S;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    int start = 0, current_sum = 0, min_length = INT_MAX;

    for (int i = 0; i< N; ++i) {
        current_sum += a[i];

        while (current_sum >= S) {
            min_length = min(min_length, i - start + 1);
            current_sum -= a[start];
            start++;
        }
    }

    if (min_length == INT_MAX) {
        cout << 0 << endl;
    } else {
        cout << min_length << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3608
final_rank: 3

code_snippet: #include<iostream>
#include<vector>
#include<climits>
using namespace std;
int main(){
int n;
int s;
cin>>n>>s;
vector<int>v(n);
for(int i=0; i<n;i++){
cin>>v[i];
}
int l=0, r=0, sum=0,mini=INT_MAX;
while(r<n){
sum+=v[r];
while(sum>=s){
mini=min(mini,r-l+1);
sum-=v[l];
l++;
}
r++;
}
if(mini==INT_MAX){
cout<<0<<endl;
}
else{
cout<<mini<<endl;
}
return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3132
final_rank: 1