Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace apps
- {
- class Program
- {
- static void Main()
- {
- //train
- // list of all numbers
- List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- // {bob number} {power}
- List<int> BombAndPower = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
- int BombNumber = BombAndPower[0];
- int BombPower = BombAndPower[1];
- // numbers equal to the bomb numbers are removed and {power} eleemnts around it are also removed
- for (int i=0; i< numbers.Count; i++) // go through all elements to see which is bombed
- {
- if (numbers[i] == BombNumber)
- {
- int ElementBombed = i; // the found index of the bombed number
- for (int y=0; y<BombPower; y++) // remove X elements from each side
- {
- if (ElementBombed - 1 >= 0)
- {
- numbers.RemoveAt(ElementBombed - 1); ElementBombed--;
- }
- if (ElementBombed+1 < numbers.Count)
- {
- numbers.RemoveAt(ElementBombed + 1);
- }
- }
- numbers.RemoveAt(ElementBombed); // finally remove the bombed element
- }
- }
- int SumTotal = 0;
- for (int i = 0; i < numbers.Count; i++) { SumTotal += numbers[i]; } // sum the elements
- Console.WriteLine(SumTotal); // print the sum of the remaining elements
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement