nikolayneykov

Untitled

Mar 6th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _05BombNumbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.             List<int> combination = Console.ReadLine().Split().Select(int.Parse).ToList();
  13.  
  14.             int bombNumber = combination[0];
  15.             int power = combination[1];
  16.             int index = numbers.IndexOf(bombNumber);
  17.  
  18.             while (index != -1)
  19.             {
  20.                 int startIndex = Math.Max(0, index - power);
  21.                 int count = Math.Min(power * 2 + 1, numbers.Count - startIndex);
  22.                 numbers.RemoveRange(startIndex, count);
  23.                 index = numbers.IndexOf(bombNumber);
  24.             }
  25.  
  26.             Console.WriteLine(numbers.Sum());
  27.         }
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment