Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _05_Bomb_Numbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
- int[] bombNumAndPower = Console.ReadLine().Split().Select(int.Parse).ToArray();
- int bombNum = bombNumAndPower[0];
- int bombPowerLeft = bombNumAndPower[1];
- int bombPowerRight = bombNumAndPower[1];
- for (int i = 0; i < numbers.Count; i++)
- {
- if (bombNum == numbers[i])
- {
- int plcsAvailLeft = i;
- int plcsAvailRight = (numbers.Count) -1 - i;
- // BOOM LEFT
- while(plcsAvailLeft > 0 && bombPowerLeft > 0)
- {
- if(bombPowerLeft > plcsAvailLeft)
- {
- bombPowerLeft--;
- continue;
- }
- numbers.RemoveAt(i - bombPowerLeft);
- bombPowerLeft--;
- i--;
- }
- bombPowerLeft = bombNumAndPower[1];
- // BOOM RIGHT
- while (plcsAvailRight > 0 && bombPowerRight > 0)
- {
- if(bombPowerRight > plcsAvailRight)
- {
- bombPowerRight--;
- continue;
- }
- numbers.RemoveAt(i + bombPowerRight);
- bombPowerRight--;
- }
- bombPowerRight = bombNumAndPower[1];
- }
- }
- // BOOM THE NUMBER
- numbers.RemoveAll(bomb => bomb == bombNum);
- Console.WriteLine(String.Join(" ", numbers.Sum()));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement