CF1251D.Salary Changing
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 li to ri 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 l1+l2+⋯+ln≤s.
Note that you don't have to spend all your s dollars on salaries.
You have to answer t test cases.
你是一家大型企业的负责人。共有 n 名员工为你工作,且 n 为奇数(即 n 不能被 2 整除)。
你需要向员工发放工资。初始时,你共有 s 美元用于支付工资,第 i 名员工的工资必须在 li 至 ri 美元之间(含端点)。你的目标是制定一种工资分配方案,使得所有员工工资序列的中位数尽可能大。
对于长度为奇数的序列,其中位数定义为:将该序列升序排序后,位于中间位置的那个元素。例如:
- 序列 [5,1,10,17,6] 的中位数为 6,
- 序列 [1,2,1] 的中位数为 1。
题目保证你有足够的资金支付所有员工的最低工资,即满足 l1+l2+⋯+ln≤s。
注意:你不必将全部 s 美元都用于发放工资。
你需要处理 t 组测试用例。
输入格式
The first line contains one integer t (1≤t≤2⋅105) — the number of test cases.
The first line of each query contains two integers n and s (1≤n<2⋅105, 1≤s≤2⋅1014) — 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 li and ri (1≤li≤ri≤109).
It is guaranteed that the sum of all n over all queries does not exceed 2⋅105.
It is also guaranteed that you have enough money to pay the minimum salary to each employee, i. e. i=1∑nli≤s.
第一行包含一个整数 t(1≤t≤2⋅105)—— 测试用例的数量。
每个查询的第一行包含两个整数 n 和 s(1≤n<2⋅105,1≤s≤2⋅1014)—— 员工人数以及你拥有的资金总额。其中 n 不被 2 整除。
每个查询的接下来 n 行描述员工信息。第 i 行包含两个整数 li 和 ri(1≤li≤ri≤109)。
保证所有查询中 n 的总和不超过 2⋅105。
还保证你拥有的资金足以支付每位员工的最低工资,即 i=1∑nli≤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: sal1=12,sal2=2,sal3=11 (sali 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: sal1=4,sal2=3,sal3=6,sal4=6,sal5=7. Then the median salary is 6.
在第一个测试用例中,你可以按如下方式发放工资:sal1=12,sal2=2,sal3=11(其中 sali 表示第 i 位员工的工资)。此时工资的中位数为 11。
在第二个测试用例中,你必须向唯一的一名员工支付 1337 美元。
在第三个测试用例中,你可以按如下方式发放工资:sal1=4,sal2=3,sal3=6,sal4=6,sal5=7。此时工资的中位数为 6。
输入解题思路,AI测评打分。不知道怎么写?