Sort of Sort

시간 제한1초메모리 제한2048 MB

요약
배열을 앞에서부터 보며 지금까지의 최댓값보다 크거나 같은 원소만 원래 순서대로 출력한다.
난이도

쉬움10점 중 3점

유형
배열, 구현
정답자
아직 제출이 없습니다

문제

Sorting takes so long... but if we don’t mind losing some data we can sort of sort much faster!

A sort of sorted list is a monotonically increasing list containing all elements of another list aa that were originally in sorted order. That is, a sort of sorted list obtained from list aa contains all a_ia\_i such that a_i≥a_ja\_i≥a\_j for all 0≤j\<i0≤j\<i.

입력

The first line of input contains a single integer NN, the length of the unsorted list (1≤N≤100,0001≤N≤100\\,000). The next line contains NN space separated integers a_ia\_i (−200,000≤a_i≤200,000-200\\,000≤a\_i≤200\\,000).

출력

Output a single line of space separated integers representing the sort of sorted list obtained from the given list aa.

예제3

  1. 예제 1

    입력
    3
    3 1 7
    
    예상 출력
    3 7
    
  2. 예제 2

    입력
    6
    1 4 3 9 7 11
    
    예상 출력
    1 4 9 11
    
  3. 예제 3

    입력
    12
    0 1 4 4 3 2 3 4 5 5 7 4
    
    예상 출력
    0 1 4 4 4 5 5 7