我的代码又运行时错误了
程序代码:
#include<iostream> #include<algorithm> using namespace std; int main(){ int w[10005]={0},n,s,ans=9999; cin>>n>>s; for(int i=1;i<=n;i++){ cin>>w[i]; } int sum=0,i,j=1; for(i=1;i<=n;i++){ while(j<=n&&sum<s){ sum+=w[j++]; } if(sum<s){ break; } ans=min(ans,j-i); sum-=w[i]; } if(ans==9999){ cout<<"-1"<<endl; } else cout<<ans<<endl; return 0; }