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 1005. Stone Pile

Runtime error. Test number - №2
Posted by Vladislav Shlyakhov 28 Mar 2019 15:46
My code, why is not working?

using System;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace Timus
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(File.OpenText("input.txt"));

            int n = Convert.ToInt32(Console.ReadLine());
            int[] numbers = new int[20];
            numbers = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int sumLeft = numbers.Max();
            numbers = pullMaxValueArray(numbers);

            int sumRight = numbers.Max();
            numbers = pullMaxValueArray(numbers);

            while(numbers.Length > 0)
            {
                int maxValue = numbers.Max();
                numbers = pullMaxValueArray(numbers);
                if (sumLeft < sumRight)
                {
                    sumLeft += maxValue;
                } else
                {
                    sumRight += maxValue;
                }
            }

            Console.WriteLine(Math.Abs(sumLeft - sumRight));
        }

        public static int [] pullMaxValueArray(int[] array)
        {
            int maxValue = array.Max();
            int maxIndex = array.ToList().IndexOf(maxValue);
            array = array.Where((source, index) => index != maxIndex).ToArray();
            return array;
        }
    }
}
Re: Runtime error. Test number - №2
Posted by Raheleh 1 Apr 2019 23:21
You do not consider inputs like:
1
1