|
|
вернуться в форумWhy is it showing wrong answer? I have given a lot of input. In my pc this program is showing correct answer all the time. Послано mars 6 апр 2020 22:32 #include<iostream> using namespace std; int main(){ int k, n, arr[101],x=0; cin>>k>>n;
for(int i=0; i<n; i++){ cin>> arr[i];
} for(int i=0;i<n;i++){ if(k>=arr[i]){ if(i != n-1){ x = x + arr[i+1]; arr[i+1] = x;
x = 0;
} else{ x = 0; }
} else{ if(i != n-1){ x = (arr[i]-k) + arr[i+1]; arr[i+1] = x;
} else{ x = arr[i] - k; } } // printf("X : %d\n",x); } if(x<=0) cout<<0; else cout<<x;
} |
|
|