Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayDeque;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] tokensValue = Arrays.stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .toArray();
- ArrayDeque<Integer> stack = new ArrayDeque<>();
- Arrays.stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .limit(tokensValue[0])
- .forEach(stack::push);
- for (int i = 0; i < tokensValue[1]; i++) {
- stack.pop();
- }
- int minValue = Integer.MAX_VALUE;
- boolean hasRequiredValue = false;
- if (stack.isEmpty()) {
- minValue = 0;
- }
- while (!stack.isEmpty() && !hasRequiredValue) {
- int number = stack.pop();
- if (number == tokensValue[2]) {
- hasRequiredValue = true;
- }
- if (number < minValue) {
- minValue = number;
- }
- }
- //Print Section
- if (hasRequiredValue) {
- System.out.println("true");
- } else {
- System.out.println(minValue);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement