SHARE
TWEET

Untitled

a guest Oct 18th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class BombNumbers {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String[] input = scanner.nextLine().split("\\s+");
  10.         List<Integer> numbers = new ArrayList<>();
  11.         for (int i = 0; i < input.length; i++) {
  12.             numbers.add(Integer.parseInt(input[i]));
  13.         }
  14.         String[] bombs = scanner.nextLine().split("\\s+");
  15.  
  16.         int bombNumber = Integer.parseInt(bombs[0]);
  17.         int power = Integer.parseInt(bombs[1]);
  18.         int sum = 0;
  19.  
  20.         while (numbers.contains(bombNumber)) {
  21.             int bombPosition = numbers.indexOf(bombNumber);
  22.             int leftBound = Math.max(0, bombPosition - power);
  23.             int rightBound = Math.min(numbers.size() - 1, bombPosition + power);
  24.  
  25.             for (int i = rightBound; i >= leftBound; i--) {
  26.                 numbers.remove(i);
  27.             }
  28.         }
  29.  
  30.         for (int i = 0; i < numbers.size(); i++) {
  31.             sum += numbers.get(i);
  32.         }
  33.         System.out.println(sum);
  34.     }
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top