Advertisement
Samanan

Untitled

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