ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1787. Turn for MEGA

Show all messages Hide all messages

Test in you code example like this
4 3
1 5 6
Wrong Answer is 0.
Thrue Answer is 3.
Be confident!!!
you are the best!!!
Re: If you have problems whit programm in test number 6!!! Sofiullah Iqbal Kiron 1 Mar 2020 14:58
Thanks
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;

}