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.

输入输出格式

输入格式


The input contains many test cases. Read until End Of File. Each test case contains n (n 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.

输出格式


For each test case output m lines containing the answers to the corresponding queries. Print an empty line after each test case.

输入输出样例

输入样例 #1

1
2
3
4
-1
-1
5
6
7
-1
0

2
3
-1
0

输出样例 #1

2
3
5

2

说明

## 题目描述 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. 题目将会按**不递减**的次序给出一些整数,每次询问中位数时需要你**输出并删除**这个数。如果剩余数的个数是偶数,选择中间两个数中较小的一个。 ## 输入输出格式 ### 输入格式: The input contains many test cases. Read until End Of File. 输入包含**多组**测试数据。**以EOF结尾**。 Each test case contains n positive integers in non-decreasing order, along with m queries indicated by -1, all on separate lines. (See the example.) 每组数据包含**n**个数...(n ≤ 100000) For a query, print the current median on a single line and remove it from the list. (此处由测试数据可得) 输入 **-1 表示查询**,用**单独的一行**输出当前的中位数,并把这个数从列表中**删除**。 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. 每组测试数据**以单行的一个 0 结尾**,两组测试数据之间会有一个**空行**分割。所有的给出整数保证用32位有符号位的数据类型存储(就是**int**啦)。询问只会在列表不为空时出现。(详情请对照样例数据) ### 输出格式: For each test case output m lines containing the answers to the corresponding queries. Print an empty line after each test case. 对于每组测试数据输出 m 行与询问相对应的答案。每组数据结尾输出一个**空行**。 由 @Kaizyn 提供翻译