emilia98

Hornet Assault

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