Guest User

Untitled

a guest
Oct 16th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 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 Bomb
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var myList = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.  
  15. int[] commands = Console.ReadLine().Split().Select(int.Parse).ToArray();
  16.  
  17. int specialNum = commands[0];
  18.  
  19. int range = commands[1];
  20.  
  21.  
  22. for (int i = 0; i < myList.Count; i++)
  23. {
  24. if (myList[i]==specialNum)
  25. {
  26. if (i-range<0)
  27. {
  28. for (int x = 0; x < i; x++)
  29. {
  30. myList[x] = 0;
  31. }
  32. for (int y = i; y <= i + range; y++)
  33. {
  34. myList[y] = 0;
  35. }
  36. }
  37. else if (i+range > myList.Count-1)
  38. {
  39. for (int x = myList.Count-1; x >= i ; x--)
  40. {
  41. myList[x] = 0;
  42.  
  43. }
  44. for (int y = i; y >= i - range; y--)
  45. {
  46. myList[y] = 0;
  47. }
  48. }
  49. else
  50. {
  51. myList.RemoveRange(i - range, range * 2 + 1);
  52. }
  53.  
  54. }
  55. }
  56.  
  57. int sum = myList.Sum();
  58. Console.WriteLine(sum);
  59. }
  60. }
  61. }
Add Comment
Please, Sign In to add comment