Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Text.RegularExpressions;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- //Console.OutputEncoding = Encoding.UTF8;
- public class Program
- {
- public static void Main()
- {
- List<int> l = new List<int>();
- int power = int.Parse(Console.ReadLine());
- string v = Console.ReadLine();
- int closest = 0;
- while (v != "All ofboard!")
- {
- int vag = int.Parse(v);
- l.Add(vag);
- if (l.Sum() > power)
- {
- int av = (int) l.Average();
- closest = l.OrderBy(x => Math.Abs(av - x)).First();
- l.Remove(closest);
- }
- v = Console.ReadLine();
- }
- l.Reverse();
- l.Add(power);
- Console.WriteLine(string.Join(" ", l));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement