Advertisement
Guest User

Untitled

a guest
Oct 25th, 2018
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 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 _05.BombNumbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.             List<int> commands = Console.ReadLine().Split().Select(int.Parse).ToList();
  15.  
  16.             for (int i = 0; i < numbers.Count; i++)
  17.             {
  18.                 if (numbers[i] == commands[0])
  19.                 {
  20.                     int start = i - commands[1];
  21.                     if (start < 0)
  22.                     {
  23.                         start = 0;
  24.                     }
  25.  
  26.                     int finish = i + commands[1] + 1;
  27.                     if (finish > numbers.Count)
  28.                     {
  29.                         finish = numbers.Count;
  30.                     }
  31.  
  32.                     for (int j = start; j < finish; j++)
  33.                     {
  34.                         numbers.RemoveAt(start);
  35.                     }
  36.                 }
  37.             }
  38.  
  39.             Console.WriteLine(numbers.Sum());
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement