Advertisement
Rayk

Untitled

Nov 1st, 2017
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03_Hornet_Assault
  6. {
  7. public class HornetAssault
  8. {
  9. public static void Main()
  10. {
  11. var beehives = Console.ReadLine().Split().Select(long.Parse).ToList();
  12. var hornets = Console.ReadLine().Split().Select(long.Parse).ToList();
  13.  
  14. var aliveBeehives = new List<long>();
  15.  
  16. foreach (var beehive in beehives)
  17. {
  18. if (hornets.Count == 0)
  19. {
  20. aliveBeehives.Add(beehive);
  21. continue;
  22. }
  23.  
  24. var hornetsPower = hornets.Sum();
  25.  
  26. if (beehive >= hornetsPower)
  27. {
  28. aliveBeehives.Add(beehive - hornetsPower);
  29. hornets.RemoveAt(0);
  30. }
  31. }
  32.  
  33. aliveBeehives = aliveBeehives.Where(bh => bh > 0).ToList();
  34. if (aliveBeehives.Count > 0)
  35. {
  36. Console.WriteLine(string.Join(" ", aliveBeehives));
  37. }
  38. else
  39. {
  40. Console.WriteLine(string.Join(" ", hornets));
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement