petarkobakov

Bomb Numbers

Jun 26th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Bomb_Numbers
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> line = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.  
  13. string[] command = Console.ReadLine().Split();
  14. int bombNum = int.Parse(command[0]);
  15. int power = int.Parse(command[1]);
  16.  
  17. int bombIndex = line.IndexOf(bombNum);
  18.  
  19. while (bombIndex !=-1)
  20. {
  21. int mostLeftIndex = bombIndex - power;
  22. int mostRightIndex = bombIndex + power;
  23.  
  24. if (mostLeftIndex<0)
  25. {
  26. mostLeftIndex = 0;
  27. }
  28.  
  29. if (mostRightIndex>line.Count-1)
  30. {
  31. mostRightIndex = line.Count - 1;
  32. }
  33.  
  34. line.RemoveRange(mostLeftIndex, mostRightIndex - mostLeftIndex + 1);
  35.  
  36. bombIndex = line.IndexOf(bombNum);
  37. }
  38.  
  39. int sum = line.Sum();
  40. Console.WriteLine(sum);
  41.  
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment