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

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.
Posted by mars 6 Apr 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;

}