Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main()
- {
- string[] input = Console.ReadLine().Split();
- int[] nums = new int[input.Length];
- List<int> lastnums = new List<int>();
- int i = 0;
- int sum = int.MinValue;
- string result = "";
- for (int j = 0; j < input.Length; j++)
- {
- nums[j] = int.Parse(input[j]);
- }
- for (i = 0; i < nums.Length - (nums.Length % 3); i += 3)
- {
- if (sum < (nums[i] + nums[i + 1] + nums[i + 2]))
- {
- sum = nums[i] + nums[i + 1] + nums[i + 2];
- result = "" + nums[i] + " " + nums[i + 1] + " " + nums[i + 2];
- }
- }
- if (nums.Length % 3 != 0)
- {
- for (; i < nums.Length; i++)
- {
- lastnums.Add(nums[i]);
- }
- int lastnumsSum = 0;
- foreach (var item in lastnums)
- {
- lastnumsSum += item;
- }
- if (sum < lastnumsSum)
- {
- result = "";
- foreach (var item in lastnums)
- {
- result += "" + item + " ";
- }
- }
- }
- Console.WriteLine(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement