List Minimum (Hard)

View as PDF

Submit solution


Points:5
Time limit:3.0s
Memory limit:256M

Problem type

Brute Force Practice 1 — Hard Version

You have a list of unique numbers each no larger than 10^9. The size of the list is no greater than 10^5. You perform the following operation on the list repeatedly: take the minimum of the numbers, and remove it from the list. You stop when the list is empty.

In what order are the numbers removed?

Input

The first line will have the size of the list.

Each line after that will be an element of the list. You are guaranteed no two elements are the same.

Output

Print one line for each time the operation was performed: the number that was removed at that step.

Sample Input

3
5
8
2

Sample Output

2
5
8

Comments


  • -7
    rahmluthor
     commented on May 10, 2017

    dislike Elvis's comment


  • -17
    Elvis
     commented on May 10, 2017

    dislike this comment please


  • -2
    Maha2006BOURAOUD
     commented on March 4, 2017

    i hate this probleme


  • 0
    FatalEagle
     commented on Oct. 22, 2016 edited
    Racket

    To deal with input/output, you may want to add this to your program:

    (void (map displayln (my-sort (build-list (read) (lambda (x) (read))) <)))


  • 0
    FatalEagle
     commented on Nov. 14, 2014
    Hint

    For Java users getting TLE on the last case, reading this might be helpful.