|
|
вернуться в форумIf you have problems whit programm in test number 6!!! Test in you code example like this 4 3 1 5 6 Wrong Answer is 0. Thrue Answer is 3. Be confident!!! Re: If you have problems whit programm in test number 6!!! Послано ryeryu 7 июл 2018 19:29 thank you! Re: If you have problems whit programm in test number 6!!! you are the best!!! Re: If you have problems whit programm in test number 6!!! Thanks Re: If you have problems whit programm in test number 6!!! Послано mars 6 апр 2020 22:33 Why this piece of code showing wrong answer. I have tested your input it has given correct output. #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;
} |
|
|