using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Biggest_Triple { class Program { static void Main(string[] args) { /*We are given n numbers, e.g. {3, 7, 2, 8, 1, 4, 6, 9}. We split them into triples: sequences of 3 consecutive numbers * (except the last sequence that could have 1 or 2 numbers). In our example, the numbers are split into these triples: * the first three numbers {3, 7, 2}; the second three numbers {8, 1, 4}; the last two numbers {6, 9}. * Write a program that enters n numbers and finds the triple with biggest sum of numbers. In our example this is the last triple: * {6, 9}. In case there are several triples with the same biggest sum, print the leftmost of them. Input The input data should be read from the console. The input data consists of exactly one line holding the input numbers, * separated one from another by a space. The input data will always be valid and in the format described. There is no need to check it explicitly. Output You have to print at the console the leftmost biggest triple as sequence of up to 3 numbers, separated by a space. Constraints • The input numbers will be integers in range [-1000 … 1000]. • The number of the input numbers n will be between 1 and 1000. • Allowed work time for your program: 0.1 seconds. • Allowed memory: 16 MB. Examples Input Output 2 5 1 4 8 2 4 8 2 1 1 1 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 4 3 3 3 0 0 9 7 1 1 2 2 3 9 2 3 4 5 5 */ //string[] numbers = Console.ReadLine().Split(' '); int n = int.Parse(Console.ReadLine()); List numbers = new List(n); for (int i = 0; i < numbers.Count; i++) { numbers[i] = int.Parse(Console.ReadLine()); } int sum = 0; List sumOfElements = new List(); for (int a = 0; a < numbers.Count; a++) { for (int b = a + 1; b < numbers.Count; b++) { for (int c = b + 1; c < numbers.Count; c++) { sum = numbers[a] + numbers[b] + numbers[c]; numbers.Remove(a); numbers.Remove(b); numbers.Remove(c); if (sum == 0) { break; } else { sumOfElements.Add(sum); } } } } for (int A = 0; A < sumOfElements.Count; A++) { for (int B = A + 1; B < sumOfElements.Count; B++) { for (int C = B + 1; C < sumOfElements.Count; C++) { if (sumOfElements[A] >= sumOfElements[B] && sumOfElements[A] >= sumOfElements[C]) { Console.WriteLine(sumOfElements[A]); } if (sumOfElements[B] >= sumOfElements[A] && sumOfElements[B] >= sumOfElements[C]) { Console.WriteLine(sumOfElements[B]); } if (sumOfElements[C] >= sumOfElements[B] && sumOfElements[C] >= sumOfElements[A]) { Console.WriteLine(sumOfElements[C]); } } } } } } }