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._BombNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> sequence = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToList();
- string[] input = Console.ReadLine().Split();
- int bombNumber = int.Parse(input[0]);
- int bombPower = int.Parse(input[1]);
- for (int i = 0; i < sequence.Count; i++)
- {
- // 1. find a bomb
- if (bombNumber == sequence[i])
- {
- int rightMostIndex = i + bombPower;
- if (rightMostIndex >= sequence.Count)
- {
- rightMostIndex = sequence.Count - 1;
- }
- int leftMostIndex = i - bombPower;
- if (leftMostIndex < 0)
- {
- leftMostIndex = 0;
- }
- // 2. detonate bombPower neighbrs.
- for (int j = leftMostIndex; j <= rightMostIndex; j++)
- {
- sequence.RemoveAt(leftMostIndex);
- }
- }
- }
- Console.WriteLine(string.Join(" ", sequence));
- // 3 print sum of left Elements
- int sum = sequence.Sum();
- Console.WriteLine(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement