vov44k

Untitled

Dec 4th, 2022
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4.  
  5. public class Main {
  6.  
  7.     static PrintWriter pw;
  8.  
  9.     public static void main(String[] args) throws FileNotFoundException {
  10.         Scanner in = new Scanner(new File("input.txt"));
  11.         pw = new PrintWriter(new File("output.txt"));
  12.  
  13.  
  14.         int n = in.nextInt();
  15.         int[] array = new int[n];
  16.  
  17.         for (int i = 0; i < n; i++) {
  18.             array[i] = in.nextInt();
  19.         }
  20.  
  21.         Stack<Integer> stack = new Stack<>();
  22.  
  23.         int k = 1;
  24.         for (int c : array) {
  25.             stack.push(c);
  26.             while (!stack.empty() && stack.peek() == k) {
  27.                 stack.pop();
  28.                 k++;
  29.             }
  30.         }
  31.         if (k != n + 1) {
  32.             pw.println(0);
  33.             pw.close();
  34.  
  35.             System.exit(0);
  36.         }
  37.  
  38.         stack.clear();
  39.         k = 1;
  40.         for (int c : array) {
  41.             stack.push(c);
  42.             pw.println(1 + " " + 1);
  43.             while (!stack.empty() && stack.peek() == k) {
  44.                 pw.println(2 + " " + 1);
  45.                 stack.pop();
  46.                 k++;
  47.             }
  48.         }
  49.  
  50.         pw.close();
  51.  
  52.     }
  53.  
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment