Get DDoS'd lol
CRISIS ALERT! AUCPL inc. has been targeted by a DDoS attack from a rogue employee, Kevin. The entire mainframe is down, but Manager Tom "The Lambda" Frew desperately needs the ongoing seed metrics for his big round bird belly.
But there is a solution! Dump all of the work to Rory the Intern!
Rory the Intern has been handed a stack of price records but Tom "The Lambda" Frew is getting antsy, and constantly wants the median seed prices.
Since rogue employee Kevin has somehow deleted Excel off everyone's computer (possibly out of spite), Rory the Intern needs to program to compute the running median quickly.
The price numbers arrive in a specific order. You need to output the median of the numbers Rory the Intern has entered so far, immediately after each number is added.
Recall that for the definition of a median:
If there are numbers in the spreadsheet, through sorting them in non-decreasing order,
- If
is odd, the median is the exact middle number
- If
is even, there are two middle elements. Since Tom "The Lambda" Frew is optimistic, Rory the Intern must report the smaller of the two middle elements.
Formally, the median is the element located at index in the 0-indexed sorted list.
Input
The first line contains a single integer (
), the total number of seed prices Rory the Intern has to enter.
The second line contains space-separated integers
(
), representing the seed prices in the exact order Rory the Intern types them into the spreadsheet.
Output
Print space-separated integers. The
-th integer should be the median of the first
seed prices.
Example
Input 1
5
10 20 5 15 30
Output 1
10 10 10 10 15
- The list is
[10]. The median is10. - The list is
[10, 20]. Even length, the two middle elements are 10 and 20. The smaller is10. - The sorted list is
[5, 10, 20]. The middle element is10. - The sorted list is
[5, 10, 15, 20]. Even length, the middle elements are 10 and 15. The smaller is10. - The sorted list is
[5, 10, 15, 20, 30]. The middle element is15.
Input 2
3
67 68 69
Output 2
67 67 68
Comments