#include <iostream> #include <cstring> #include <string> #include <algorithm> #include <cstdio> using namespace std; #define maxn 100000 #define INF 0x7ffffff int n, S, a[maxn]; void solve() { int s = 0, t = 0; int res = INF; int sum = 0; for(;;) { while(t < n && sum < S) sum += a[t++]; if(sum < S) break; res = min(res, t - s); sum -= a[s++]; } if(res != INF) cout<<res<<endl; else cout<<0<<endl; } int main() { int T; cin>>T; while(T--) { cin>>n>>S; for(int i=0; i<n; i++) scanf("%d", &a[i]); solve(); } return 0; }
原文地址:http://blog.csdn.net/dojintian/article/details/45064675