Submeter | Todas submissőes | Melhores | Voltar |
Problem hidden
RMID - Running Median |
You will be given some integers in non decreasing order and each time the median is queried you have to report and remove it. Take the smaller element as median in case of even elements.
Input
The input contains many test cases. Read until End Of File.
Each test case contains n (n ≤ 100000) positive integers in non-decreasing order, along with m queries indicated by -1, all on separate lines. (See the example.)
For a query, print the current median on a single line and remove it from the list.
Each test case ends with 0 on a single line, and two test cases will be separated by an empty line. All integers are guaranteed to fit in a signed 32-bit container. A query can only occur if the list is non-empty.
Output
For each test case output m lines containing the answers to the corresponding queries. Print an empty line after each test case.
Example
Input: 1 2 3 4 -1 -1 5 6 7 -1 0 2 3 -1 0 Output: 2 3 5 2
Adicionado por: | jayant mukherji |
Data: | 2013-07-12 |
Tempo limite: | 0.5s |
Tamanho do fonte: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Linguagem permitida: | ADA95 ASM32 GAWK BASH BF C CSHARP C++ 4.3.2 CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN GO HASK ICON ICK JAVA JS-RHINO LUA NEM NICE NODEJS OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON PYTHON3 RUBY SCM guile SCM qobi SED ST WHITESPACE |