아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Interview Queue

면접 대비

시간 제한4초메모리 제한1024 MB

요약
이웃한 지원자 중 자신보다 큰 값이 있으면 매 분 이탈한다는 규칙 아래, 각 지원자가 이탈하는 시각과 최종 대기열을 구한다.
난이도

보통10점 중 6점

유형
시뮬레이션, 스택, 배열, 구현
정답자
아직 제출이 없습니다

문제

A very popular position has just opened up at Poodle Inc. Candidates have formed a queue while they wait for their turn to be interviewed.

Competition is fierce and each candidate knows that they will not be selected if another candidate is strictly better than them. Every minute, each candidate looks at the resumé of candidates who are currently adjacent to them in the queue (ahead and behind). If at least one of the neighbour's resumé's perceived value is strictly greater than their resumé's perceived value, they leave the queue since they do not want to waste their time. The candidates all look at their neighbor's resumé simultaneously, and then some candidates leave the queue simultaneously.

This process continues until no more candidates leave the queue. Determine the number of minutes that pass while this process takes place. Report the values of the candidates that leave the queue in each round. Also report the final state of the queue.

입력

The first line of input contains a single integer NN (1≤N≤100,0001 \leq N \leq 100\\,000), which is the number of candidates.

The second line contains NN integers v_1,…,v_Nv\_1, \ldots, v\_N (0≤v_i≤1090 \leq v\_i \leq 10^9 for each 1≤i≤N1 \leq i \leq N), where v_iv\_i is the perceived value of the ithi^\textrm{th} candidate.

출력

Display MM, the number of minutes taken by this process. Then display MM lines. The ithi^\textrm{th} line should contain the perceived values of the candidates who left the queue in the ithi^\textrm{th} minute in the same relative order that they appeared in the queue. Finally display a line indicating the final list of perceived values in the queue after candidates no longer leave it.

예제3

  1. 예제 1

    입력
    10
    3 6 2 3 2 2 2 1 5 6
    
    예상 출력
    2
    3 2 2 1 5
    3 2 2
    6 6
    
  2. 예제 2

    입력
    3
    17 17 17
    
    예상 출력
    0
    17 17 17
    
  3. 예제 3

    입력
    7
    8 1 2 3 5 6 7
    
    예상 출력
    2
    1 2 3 5 6
    7
    8