|
|
back to boardRuntime error. Test number - №2 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 You do not consider inputs like: 1 1 |
|
|