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 Terekhin Grigory 1 Mar 2018 15:32
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace РџРѕРІРѕСЂРѕС‚
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] mas = Console.ReadLine().Split(' ');
            int k = int.Parse(mas[0]);
            int n = int.Parse(mas[1]);
            int[] A = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(i => int.Parse(i)).ToArray();
            int M = 0;
            for (int i = 0; i < n; i++)
            {
                M += A[i];
                if (M - k >= 0)
                {M -= k;}
                else
                {M = 0;}
            }
            Console.WriteLine(M);
        }
    }
}
Надеюсь понятно всё.