#P9559. [SDCPC2023] Fast and Fat
[SDCPC2023] 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 .