标签:
感觉还不错又简单的的一个题
#include <cstdio> #include <algorithm> using namespace std; const int maxn = 100005; const int INF = 0x3f3f3f3f; int a[maxn]; int main() { // freopen("in.txt","r",stdin); int n,s; while(~scanf("%d%d",&n,&s)) { int sum = 0,ans = INF,p = 1; for(int i = 1;i<=n;++i) { scanf("%d",a+i); sum+=a[i]; while(sum>=s) { if(sum-a[p]<s)break; sum-=a[p++]; ans = min(ans,i-p+1); } } if(ans>=INF)ans = 0; printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/GJKACAC/p/4241320.html