Advertisement
Guest User

BombNumbers

a guest
Jun 8th, 2016
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _12.Bomb_Numbers
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var numbers = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  14.  
  15. int[] commands = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  16. int specialNumber = commands[0];
  17. int offset = numbers.IndexOf(specialNumber);
  18. int power = commands[1];
  19. while (numbers.IndexOf(specialNumber) == -1)
  20. {
  21. int startIndex = Math.Max(0, offset - power);
  22. int countToRemove = Math.Min(power*2 + 1, Math.Abs(numbers.Count - startIndex));
  23. numbers.RemoveRange(startIndex, countToRemove);
  24.  
  25. offset = numbers.IndexOf(specialNumber);
  26. }
  27.  
  28.  
  29. Console.WriteLine(numbers.Sum());
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement