306786: CF1251D. Salary Changing

Memory Limit:256 MB Time Limit:3 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Salary Changing

题意翻译

您是一个大型企业的负责人(WoW)。在您的企业当中共有$n$位员工为您工作,而且非常有趣的事是这个$n$是一个奇数($n$不能被$2$整除)。 您必须给你的员工分配工资。最初,您有$s$美元,而第$i$个员工应得的薪水应该是$l_i\sim r_i$之间的一个值。而无论怎么分配每个人的工资,您必须使得所有分配的工资的中位数最大。 对于一个长度为奇数的序列,如果要找到他的中位数,就需要先对这个序列进行排序,之后找到中间位置的数字。举例来说: - 序列$[5,1,10,17,6]$的中位数是$6$ - 序列$[1,2,1]$的中位数是$1$ 保证您有足够的钱来支付最低的工资,即$l_1+l_2+ \dots +l_n \le s$。 注意,您不必把所有的钱都花在员工的开支上。 一共有$t$组测试样例。 ------ **简洁题面:** 你的公司中有$n$个员工($n$是一个奇数),你需要给他们分配薪水。起初你有$s$美元,而对于第$i$位员工,他的薪水应该是在$l_i \sim r_i$之间的。而你必须使所有员工分配到的工资的中位数最大。 数据保证你有足够的钱来支付每个员工的最低工资,你也不一定都要把所有的钱都花光。 询问这个最大的中位数是多少。 共有$t$组测试样例。

题目描述

You are the head of a large enterprise. $ n $ people work at you, and $ n $ is odd (i. e. $ n $ is not divisible by $ 2 $ ). You have to distribute salaries to your employees. Initially, you have $ s $ dollars for it, and the $ i $ -th employee should get a salary from $ l_i $ to $ r_i $ dollars. You have to distribute salaries in such a way that the median salary is maximum possible. To find the median of a sequence of odd length, you have to sort it and take the element in the middle position after sorting. For example: - the median of the sequence $ [5, 1, 10, 17, 6] $ is $ 6 $ , - the median of the sequence $ [1, 2, 1] $ is $ 1 $ . It is guaranteed that you have enough money to pay the minimum salary, i.e $ l_1 + l_2 + \dots + l_n \le s $ . Note that you don't have to spend all your $ s $ dollars on salaries. You have to answer $ t $ test cases.

输入输出格式

输入格式


The first line contains one integer $ t $ ( $ 1 \le t \le 2 \cdot 10^5 $ ) — the number of test cases. The first line of each query contains two integers $ n $ and $ s $ ( $ 1 \le n < 2 \cdot 10^5 $ , $ 1 \le s \le 2 \cdot 10^{14} $ ) — the number of employees and the amount of money you have. The value $ n $ is not divisible by $ 2 $ . The following $ n $ lines of each query contain the information about employees. The $ i $ -th line contains two integers $ l_i $ and $ r_i $ ( $ 1 \le l_i \le r_i \le 10^9 $ ). It is guaranteed that the sum of all $ n $ over all queries does not exceed $ 2 \cdot 10^5 $ . It is also guaranteed that you have enough money to pay the minimum salary to each employee, i. e. $ \sum\limits_{i=1}^{n} l_i \le s $ .

输出格式


For each test case print one integer — the maximum median salary that you can obtain.

输入输出样例

输入样例 #1

3
3 26
10 12
1 4
10 11
1 1337
1 1000000000
5 26
4 4
2 4
6 8
5 6
2 7

输出样例 #1

11
1337
6

说明

In the first test case, you can distribute salaries as follows: $ sal_1 = 12, sal_2 = 2, sal_3 = 11 $ ( $ sal_i $ is the salary of the $ i $ -th employee). Then the median salary is $ 11 $ . In the second test case, you have to pay $ 1337 $ dollars to the only employee. In the third test case, you can distribute salaries as follows: $ sal_1 = 4, sal_2 = 3, sal_3 = 6, sal_4 = 6, sal_5 = 7 $ . Then the median salary is $ 6 $ .

Input

题意翻译

您是一个大型企业的负责人(WoW)。在您的企业当中共有$n$位员工为您工作,而且非常有趣的事是这个$n$是一个奇数($n$不能被$2$整除)。 您必须给你的员工分配工资。最初,您有$s$美元,而第$i$个员工应得的薪水应该是$l_i\sim r_i$之间的一个值。而无论怎么分配每个人的工资,您必须使得所有分配的工资的中位数最大。 对于一个长度为奇数的序列,如果要找到他的中位数,就需要先对这个序列进行排序,之后找到中间位置的数字。举例来说: - 序列$[5,1,10,17,6]$的中位数是$6$ - 序列$[1,2,1]$的中位数是$1$ 保证您有足够的钱来支付最低的工资,即$l_1+l_2+ \dots +l_n \le s$。 注意,您不必把所有的钱都花在员工的开支上。 一共有$t$组测试样例。 ------ **简洁题面:** 你的公司中有$n$个员工($n$是一个奇数),你需要给他们分配薪水。起初你有$s$美元,而对于第$i$位员工,他的薪水应该是在$l_i \sim r_i$之间的。而你必须使所有员工分配到的工资的中位数最大。 数据保证你有足够的钱来支付每个员工的最低工资,你也不一定都要把所有的钱都花光。 询问这个最大的中位数是多少。 共有$t$组测试样例。

加入题单

算法标签: