Advertisement
YavorGrancharov

Hornet_Assault(80%)

Aug 10th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Hornet_Assault
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             long[] beehives = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
  12.             long[] hornets = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
  13.  
  14.             long hornetsSumPower = 0;
  15.             for (int i = 0; i < hornets.Length; i++)
  16.             {
  17.                 hornetsSumPower += hornets[i];
  18.             }
  19.  
  20.             List<long> aliveBees = new List<long>();
  21.             List<long> aliveHornets = hornets.ToList();
  22.  
  23.             long aliveBee = 0;
  24.             for (int i = 0; i < beehives.Length; i++)
  25.             {
  26.                 if (hornetsSumPower <= beehives[i])
  27.                 {
  28.                     aliveBee = beehives[i] - hornetsSumPower;
  29.                     if (aliveBee != 0)
  30.                     {
  31.                         aliveBees.Add(aliveBee);
  32.                     }
  33.                     hornetsSumPower -= aliveHornets[0];
  34.                     aliveHornets.Remove(aliveHornets[0]);
  35.                 }
  36.             }
  37.  
  38.             if (aliveBees.Sum() > 0)
  39.             {
  40.                 Console.WriteLine(string.Join(" ", aliveBees));
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine(string.Join(" ", aliveHornets));
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement