MiroslavKisov

HornetAssault

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