CF2200F.Mooclear Reactor 2

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Bessie needs to produce energy as possible in her mooclear reactor. She has nn different particles.

Each particle is defined by two integers xx and yy. The particle generates xx units of energy but has a reactivity yy, meaning that it can only exist together with at most yy other particles in the reactor. Formally, if this particle is chosen to generate energy, then at most yy particles (other than itself) can also be chosen to generate energy.

Bessie must choose a subset of particles that satisfy this constraint to generate energy. The amount of energy that she generates is equal to the sum of the energies of the particles in the subset.

There is a shop with mm particles. Bessie can buy exactly one particle from the shop. For each particle in the shop, determine the maximum total energy that Bessie would be able to produce if she were to buy only that particle from the shop. Bessie is not required to use the particle that is purchased from the shop.

贝茜需要在她的“牛核”反应堆中尽可能多地产生能量。她拥有 nn 种不同的粒子。

每种粒子由两个整数 xx 和 yy 定义:该粒子可产生 xx 单位能量,但其反应活性为 yy,意味着它最多只能与 yy 个其他粒子共存于反应堆中。形式化地说,若选择该粒子来产生能量,则至多还能再选择 yy 个(除自身外的)粒子来产生能量。

贝茜必须选择一个满足上述约束的粒子子集来产生能量。她所生成的总能量等于该子集中所有粒子的能量之和。

现有一家商店,其中出售 mm 种粒子。贝茜恰好可以从该商店购买一种粒子。对商店中的每种粒子,请计算:若贝茜仅购买该粒子(即从商店中只购入这一种粒子),则她所能产生的最大总能量是多少?注意:贝茜并非必须使用从商店中购买的粒子。

输入格式

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

The first line of each test case contains two integers nn and mm (1≤n,m≤2⋅1051 \leq n, m \leq 2 \cdot 10^5) — the number of particles that Bessie has and the number of particles in the shop, respectively.

The ii-th of the next nn lines contains two integers xx and yy (1≤x≤1091 \leq x \leq 10^9, 0≤y≤n0 \leq y \leq n) — the energy and reactivity of Bessie's ii-th particle.

The jj-th of the next mm lines contains two integers xx and yy (1≤x≤1091 \leq x \leq 10^9, 0≤y≤n0 \leq y \leq n) — the energy and reactivity of the shop's jj-th particle.

It is guaranteed that the sum of nn over all test cases and the sum of mm over all test cases do not exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤2⋅1051 \leq n, m \leq 2 \cdot 10^5)——分别表示贝茜拥有的粒子数量以及商店中粒子的数量。

接下来的 nn 行中,第 ii 行包含两个整数 xx 和 yy(1≤x≤1091 \leq x \leq 10^9,0≤y≤n0 \leq y \leq n)——表示贝茜的第 ii 个粒子的能量和反应性。

再接下来的 mm 行中,第 jj 行包含两个整数 xx 和 yy(1≤x≤1091 \leq x \leq 10^9,0≤y≤n0 \leq y \leq n)——表示商店中第 jj 个粒子的能量和反应性。

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

输出格式

For each test case, print mm integers. The ii-th integer should be the maximum total energy that Bessie can produce if she purchases the ii-th particle from the shop.

对于每个测试用例,输出 mm 个整数。其中第 ii 个整数表示:如果贝茜从商店购买第 ii 个粒子,她所能产生的最大总能量。

输入输出样例

  • 输入#1

    3
    3 3
    67 0
    6 1
    7 1
    1 0
    100 0
    62 1
    2 1
    2 2
    4 2
    3 1
    1 2
    6 1
    7 0
    8 1

    输出#1

    67 100 69
    7
    7 14

说明/提示

In the first test case:

  • If Bessie buys particle 44, then it is optimal for her to only use particle 11 and generate 6767 energy units.
  • If she buys particle 55, then she should only use particle 55, which generates 100100 energy units.
  • If she buys particle 66, then she should use particles 33 and 66, for a total of 6969 energy units.

在第一个测试用例中:

  • 如果贝茜购买粒子 44,那么她只使用粒子 11 是最优的,可产生 6767 单位能量。
  • 如果她购买粒子 55,那么她应仅使用粒子 55,可产生 100100 单位能量。
  • 如果她购买粒子 66,那么她应使用粒子 33 和粒子 66,总共产生 6969 单位能量。

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

首页