CF1839B.Lamps

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have nn lamps, numbered by integers from 11 to nn. Each lamp ii has two integer parameters aia_i and bib_i.

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 bib_i points for turning lamp ii on. The following happens after each performed operation:

  • Let's denote the number of lamps that are turned on as xx (broken lamps do not count). All lamps ii such that ai≤xa_i \le x 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.

你有 nn 盏灯,编号为从 11 到 nn 的整数。每盏灯 ii 有两个整数参数 aia_i 和 bib_i。

在任意时刻,每盏灯处于以下三种状态之一:开启、关闭或损坏。

初始时所有灯均处于关闭状态。每次操作中,你可以选择一盏当前处于关闭状态的灯并将其开启(不能开启已损坏的灯)。开启灯 ii 会为你获得 bib_i 分。每次执行完一次操作后,会发生如下事件:

  • 设当前处于开启状态的灯的数量为 xx(损坏的灯不计入此数量)。那么所有满足 ai≤xa_i \le x 的灯 ii 将同时损坏,无论其此前是开启还是关闭状态。

请注意:损坏的灯永远不被计为开启状态;并且,若一盏已开启的灯随后损坏,你仍保留此前开启它所获得的分数。

你可以执行任意次数的操作。

求你能获得的最大分数。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

The first line contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of lamps.

Each of the next nn lines contains two integers aia_i and bib_i (1≤ai≤n,1≤bi≤1091 \le a_i \le n, 1 \le b_i \le 10^9) — parameters of the ii-th lamp.

It is guaranteed that sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 灯的数量。

接下来的 nn 行中,每行包含两个整数 aia_i 和 bib_i(1≤ai≤n, 1≤bi≤1091 \le a_i \le n,\ 1 \le b_i \le 10^9)—— 第 ii 盏灯的参数。

保证所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output one integer — the maximum number of points you can get.

对于每个测试用例,输出一个整数——你能获得的最高分数。

输入输出样例

  • 输入#1

    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

    输出#1

    15
    14
    20
    1

说明/提示

In first test case n=4n = 4. One of ways to get the maximum number of points is as follows:

  • You turn lamp 44 on and receive b4=13b_4 = 13 points.
  • The number of lamps that are turned on is 11, so all lamps with ai≤1a_i \le 1 (namely lamps 22, 33 and 44) break. Lamp 44 is no longer turned on, so the number of lamps that are turned becomes 00.
  • The only lamp you can turn on is lamp 11, as all other lamps are broken. You receive b1=2b_1 = 2 points for turning it on.
  • The number of lamps that are turned on is 11. As a1=2a_1 = 2, lamp 11 doesn't break.

Your receive 13+2=1513 + 2 = 15 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 1515.

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 44 and receive 22 points. No lamps break after the first operation.
  • On the second operation you turn on lamp 33 and receive 55 points. After the second operation, there are 22 lamps turned on. As a3≤2a_3 \le 2, lamp 33 breaks.
  • On the third operation, you turn on lamp 11 and receive 44 points.
  • On the fourth operation, you turn on lamp 55 and receive 33 points. After that there are 33 lamps turned on: lamps 11, 44 and 55. Lamps 11, 22, 44 and 55 simultaneously break, because for all of them ai≤3a_i \le 3.

You receive 2+5+4+3=142 + 5 + 4 + 3 = 14 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 33 on and receive 44 points. Lamps 11 and 33 break.
  • Turn the lamp 22 on and receive 44 points.
  • Turn the lamp 66 on and receive 33 points. Lamp 66 breaks.
  • Turn the lamp 44 on and receive 44 points.
  • Turn the lamp 55 on and receive 55 points. Lamps 22, 44 and 55 break.

You receive 4+4+3+4+5=204 + 4 + 3 + 4 + 5 = 20 points in total. It can be shown that this is the maximum number of points you can get.

在第一个测试用例中,n=4n = 4。获得最多分数的一种方式如下:

  • 打开第 44 盏灯,获得 b4=13b_4 = 13 分。
  • 此时已打开的灯的数量为 11,因此所有满足 ai≤1a_i \le 1 的灯(即第 22、33、44 盏灯)损坏。第 44 盏灯不再处于开启状态,故已打开的灯的数量变为 00。
  • 此时唯一可打开的灯是第 11 盏灯(其余灯均已损坏),打开它可获得 b1=2b_1 = 2 分。
  • 此时已打开的灯的数量为 11;由于 a1=2a_1 = 2,第 11 盏灯不会损坏。

你总共获得 13+2=1513 + 2 = 15 分。可以证明这是你能获得的最大分数,因此第一个测试用例的答案为 1515。

在第二个测试用例中,获得最多分数的一种方式如下:

  • 第一次操作:打开第 44 盏灯,获得 22 分。第一次操作后没有灯损坏。
  • 第二次操作:打开第 33 盏灯,获得 55 分。第二次操作后,共有 22 盏灯被打开;由于 a3≤2a_3 \le 2,第 33 盏灯损坏。
  • 第三次操作:打开第 11 盏灯,获得 44 分。
  • 第四次操作:打开第 55 盏灯,获得 33 分。此时共有 33 盏灯被打开:第 11、44、55 盏灯。第 11、22、44、55 盏灯同时损坏,因为对它们均有 ai≤3a_i \le 3。

你总共获得 2+5+4+3=142 + 5 + 4 + 3 = 14 分。可以证明这是你能获得的最大分数。

在第三个测试用例中,获得最多分数的一种方式如下:

  • 打开第 33 盏灯,获得 44 分;第 11 和第 33 盏灯损坏。
  • 打开第 22 盏灯,获得 44 分。
  • 打开第 66 盏灯,获得 33 分;第 66 盏灯损坏。
  • 打开第 44 盏灯,获得 44 分。
  • 打开第 55 盏灯,获得 55 分;第 22、44、55 盏灯损坏。

你总共获得 4+4+3+4+5=204 + 4 + 3 + 4 + 5 = 20 分。可以证明这是你能获得的最大分数。

输入解题思路,AI测评打分。不知道怎么写?

首页