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.
输入格式
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 .
输出格式
For each test case, output one integer — the maximum number of points you can get.
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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)