Smallest Element After RemovalsEasy

Smallest Element After Removals

EasyPractice library · +10 XPheapspriority queues

You are given a list of N integers. You need to perform the following operation K times: find the smallest element in the list, remove it, and print its value. After performing K operations, you should also print the smallest element remaining in the list (if any). If the list becomes empty during the operations, stop removing elements and print 'empty' for subsequent removals and the final remaining element.

Tie-breaking: If there are multiple occurrences of the smallest element, remove and print any one of them. The final smallest element should be printed.

Input

The first line contains two integers N and K, separated by a space. The second line contains N integers, representing the list of numbers.

Output

Print K+1 lines. Each of the first K lines should contain the smallest element removed in that operation. The (K+1)-th line should contain the smallest element remaining in the list after K removals, or 'empty' if the list is empty.

Constraints

1 <= N <= 1000 1 <= K <= N -10^9 <= numbers in the list <= 10^9

Time limit 1 s (native code; slower languages get more)Memory 256 MB13 hidden tests

Example 1

Input
5 3
3 1 4 1 5
Output
1
1
3
4

Removes 1, then 1, then 3. The smallest remaining is 4.

Example 2

Input
3 5
10 20 30
Output
10
20
30
empty
empty
empty

Removes 10, 20, 30. List becomes empty. Then prints 'empty' twice more. The final remaining is 'empty'.

Hints