欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1839B.Lamps
Lamps
You have lamps, numbered by integers from to . Each lamp has two integer parameters and .
At each moment each lamp is in one of three states: it may be turned on, turned off, or broken.
Initially all lamps are turned off. In one operation you can select one lamp that is turned off and turn it on (you can't turn on broken lamps). You receive points for turning lamp on. The following happens after each performed operation:
- Let's denote the number of lamps that are turned on as (broken lamps do not count). All lamps such that simultaneously break, whether they were turned on or off.
Please note that broken lamps never count as turned on and that after a turned on lamp breaks, you still keep points received for turning it on.
You can perform an arbitrary number of operations.
Find the maximum number of points you can get.
Input
The first line contains a single integer () — the number of test cases.
The first line contains a single integer () — the number of lamps.
Each of the next lines contains two integers and () — parameters of the -th lamp.
It is guaranteed that sum of over all test cases doesn't exceed .
Output
For each test case, output one integer — the maximum number of points you can get.
Note
In first test case . One of ways to get the maximum number of points is as follows:
- You turn lamp on and receive points.
- The number of lamps that are turned on is , so all lamps with (namely lamps , and ) break. Lamp is no longer turned on, so the number of lamps that are turned becomes .
- The only lamp you can turn on is lamp , as all other lamps are broken. You receive points for turning it on.
- The number of lamps that are turned on is . As , lamp doesn't break.
Your receive points in total. It can be shown that this is the maximum number of points you can get, so the answer for the first test case is .
In the second test case, one of the ways to get the maximum number of points is as follows:
- On the first operation you turn on lamp and receive points. No lamps break after the first operation.
- On the second operation you turn on lamp and receive points. After the second operation, there are lamps turned on. As , lamp breaks.
- On the third operation, you turn on lamp and receive points.
- On the fourth operation, you turn on lamp and receive points. After that there are lamps turned on: lamps , and . Lamps , , and simultaneously break, because for all of them .
You receive points in total. It can be shown that this is the maximum number of points you can get.
In the third test case, one of the ways to get the maximum number of points is as follows:
- Turn the lamp on and receive points. Lamps and break.
- Turn the lamp on and receive points.
- Turn the lamp on and receive points. Lamp breaks.
- Turn the lamp on and receive points.
- Turn the lamp on and receive points. Lamps , and break.
You receive points in total. It can be shown that this is the maximum number of points you can get.
Samples
4
4
2 2
1 6
1 10
1 13
5
3 4
3 1
2 5
3 2
3 3
6
1 2
3 4
1 4
3 4
3 5
2 3
1
1 1
15
14
20
1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |