Ledger Nano X - The secure hardware wallet
SHARE
TWEET

DiskTower

Bobjoehi Apr 4th, 2020 (edited) 223 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.util.*;
  3. public class DiskTower {
  4.     public static void main(String[] args) throws IOException{
  5.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  6.         int n = Integer.parseInt(in.readLine());
  7.         PriorityQueue<Integer> q = new PriorityQueue<Integer>(n, Collections.reverseOrder());
  8.         StringTokenizer st = new StringTokenizer(in.readLine());
  9.        
  10.         int next = n;
  11.         for(int i = 0; i < n; i ++) {
  12.             int d = Integer.parseInt(st.nextToken());
  13.             q.offer(d);
  14.             while(!q.isEmpty() && q.peek() == next) {
  15.                 System.out.print(q.poll() + " ");
  16.                 next --;
  17.             }
  18.             System.out.println();
  19.         }
  20.     }
  21. }
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