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

ответ на С++
Posted by Anastasiya 16 Jan 2018 11:11
#include <iostream>
using namespace std;

int main()
{
    int k, n, res=0;
    cin >> k >> n;
    int *mas = new int[n];

    for (int i=0; i!=n; i++)
    {
        cin >> mas[i];

        if (mas[i] > k)
        {
            res = res + (mas[i] - k);
        }
        else
        {
            if (res!=0 )
            {
                if ((k - mas[i]) > res)
                {
                    res = 0;
                }
                else
                {
                    res = res - (k - mas[i]);
                }
            }
        }

    }
    cout << res;

    return 0;
}
Re: ответ на С++
Posted by Orient 17 Jan 2018 14:42
This is the mean.

Edited by author 17.01.2018 14:44