#P9559. [SDCPC 2023] Fast and Fat
[SDCPC 2023] Fast and Fat
题目描述
You're participating in a team competition of trail running. There are members in your team where is the speed of the -th member and is his/her weight.
The competition allows each team member to move alone or carry another team member on their back. When member carries member , if member 's weight is greater than or equal to member 's weight, member 's speed remains unchanged at . However, if member 's weight is less than member 's weight, member 's speed will decrease by the difference of their weight and becomes . If member 's speed will become negative, then member is not able to carry member . Each member can only carry at most one other member. If a member is being carried, he/she cannot carry another member at the same time.
For all members not being carried, the speed of the slowest member is the speed of the whole team. Find the maximum possible speed of the whole team.
输入格式
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains an integer () indicating the number of team members.
For the following lines, the -th line contains two integers and () indicating the speed and weight of the -th member.
It's guaranteed that the sum of of all test cases will not exceed .
输出格式
For each test case output one line containing one integer indicating the maximum speed of the whole team.
2
5
10 5
1 102
10 100
7 4
9 50
2
1 100
10 1
8
1
提示
The optimal strategy for the sample test case is shown as follows:
- Let member carry member . As , member 's speed remains unchanged, which is still .
- Let member carry member . As , member 's speed will decrease by and becomes .
- Member shall move alone. His/Her speed is .
So the answer is .