|
|
вернуться в форумwhy WA1!!! Please help!! #include<iostream> using namespace std; int main() { int k,n,a[1001],i,j=0,ans[1001]={0},sum; cin>>k>>n; for(i=0;i<n;i++) {cin>>a[i];} for(i=0;i<n;i++) { if((ans[i-1]+a[i])-k<=0){ans[i]=0;} else if((ans[i-1]+a[i])-k<=0 and ans[i-1]>0){ans[i]=k-a[i]+ans[i-1];} else if((ans[i-1]+a[i])-k>0 and ans[i-1]>0) {ans[i]=a[i]+ans[i-1]-k;} else if((ans[i-1]+a[i])-k>0 and ans[i-1]==0){ans[i]=a[i]-k;} }
cout<<ans[n-1]<<endl; system("pause"); return 0;} Edited by author 15.11.2012 12:40 |
|
|