Advertisement
ivanov_ivan

BombKur

Oct 12th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace BombNumbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> someList = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse).ToList();
  13.  
  14.             int[] bombKur = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  15.                 .Select(int.Parse).ToArray();
  16.  
  17.             int startIndex = someList.IndexOf(bombKur[0]);
  18.  
  19.             while (startIndex != -1)
  20.             {
  21.                 int beginIndex = Math.Max(0, startIndex - bombKur[1]);
  22.                 int endIndex = Math.Min(someList.Count - 1, startIndex + bombKur[1]);
  23.  
  24.                 someList.RemoveRange(beginIndex, endIndex - beginIndex + 1);
  25.                 startIndex = someList.IndexOf(bombKur[0]);
  26.             }
  27.  
  28.             Console.WriteLine(someList.Sum());
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement