Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Близнецы
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- int n; //Количество монет
- int[] money;//Массив для монет
- int totalSum = 0;//Вся сумма
- int currentSum = 0;//Текущая сумма
- double halfSum;//Половина суммы
- int count = 0;//Счётчик монет
- using(var sr = new StreamReader("input.txt"))
- {
- n = int.Parse(sr.ReadLine());
- string[] str = sr.ReadLine().Split(' ');
- money = new int[n];
- for (int i = 0; i < n; i++)//Заполняем массив монетами
- {
- money[i] = int.Parse(str[i]);
- totalSum += money[i];
- }
- Array.Sort(money);//Сортируем массив
- Array.Reverse(money);//Переворачиваем задом-наперед
- double temp = totalSum / 2;
- halfSum = Math.Ceiling(temp);//Находим половину суммы монет, округляя в большую сторону
- }
- while(currentSum <= halfSum)//Пока текущая сумма меньше или равна половине, берём монеты начиная с самых больших (т.к. массив отсортирован и перевёрнут)
- {
- currentSum += money[count];
- count++;
- }
- Console.WriteLine(count);//Выводим ответ
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement