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

If you have problems whit programm in test number 6!!!
Posted by polskyLIDER 5 Mar 2017 21:11
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!!!
Posted by ryeryu 7 Jul 2018 19:29
thank you!
Re: If you have problems whit programm in test number 6!!!
Posted by buyolitsez 17 Oct 2018 22:15
you are the best!!!
Re: If you have problems whit programm in test number 6!!!
Posted by Sofiullah Iqbal Kiron 1 Mar 2020 14:58
Thanks
Re: If you have problems whit programm in test number 6!!!
Posted by mars 6 Apr 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;

}