Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.Collections;
- import java.util.Scanner;
- public class InspirationLab {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- ArrayDeque<Integer> queue = new ArrayDeque<>();
- String[] commands = sc.nextLine().split("\\s+");
- String[] nums = sc.nextLine().split("\\s+");
- int N = Integer.parseInt(commands[0]);//add
- int S = Integer.parseInt(commands[1]);//remove/poll
- int X = Integer.parseInt(commands[2]);//true X or smallest
- for (int i = 0; i < N; i++) {
- int toAdd = Integer.parseInt(nums[i]);
- queue.add(toAdd);
- }
- for (int i = 0; i < S; i++) {
- if(!queue.isEmpty()) {
- queue.remove();
- }
- }
- if (queue.contains(X)) {
- System.out.println("true");
- } else {
- if (!queue.isEmpty()) {
- int start = queue.peek();
- for (int i = 0; i < queue.size(); i++) {
- int currentNum = queue.peek();
- if (currentNum < start) {
- start = currentNum;
- }
- }
- System.out.println(start);
- } else {
- System.out.println(0);
- }
- }
- }
- }
- //4 1 666
- //666 69 13 420
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement