CF1354F.Summoning Minions

省选/NOI-

通过率:0%

时间限制:6.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.

Polycarp can summon nn different minions. The initial power level of the ii-th minion is aia_i, and when it is summoned, all previously summoned minions' power levels are increased by bib_i. The minions can be summoned in any order.

Unfortunately, Polycarp cannot have more than kk minions under his control. To get rid of unwanted minions after summoning them, he may destroy them. Each minion can be summoned (and destroyed) only once.

Polycarp's goal is to summon the strongest possible army. Formally, he wants to maximize the sum of power levels of all minions under his control (those which are summoned and not destroyed).

Help Polycarp to make up a plan of actions to summon the strongest possible army!

波利卡普正在玩一款电脑游戏。在这款游戏中,玩家召唤魔法仆从组成的军队,这些军队随后相互战斗。

波利卡普可以召唤 nn 种不同的仆从。第 ii 个仆从的初始力量值为 aia_i;当它被召唤时,所有此前已召唤的仆从的力量值均增加 bib_i。仆从可以按任意顺序召唤。

不幸的是,波利卡普最多只能同时控制 kk 个仆从。为了在召唤后移除不需要的仆从,他可以选择将它们摧毁。每个仆从至多只能被召唤(并摧毁)一次。

波利卡普的目标是召唤尽可能强大的军队。形式化地说,他希望最大化其当前所控制的所有仆从(即已召唤且未被摧毁者)的力量值之和。

请帮助波利卡普制定一套行动方案,以召唤出尽可能强大的军队!

输入格式

The first line contains one integer TT (1≤T≤751 \le T \le 75) — the number of test cases.

Each test case begins with a line containing two integers nn and kk (1≤k≤n≤751 \le k \le n \le 75) — the number of minions availible for summoning, and the maximum number of minions that can be controlled by Polycarp, respectively.

Then nn lines follow, the ii-th line contains 22 integers aia_i and bib_i (1≤ai≤1051 \le a_i \le 10^5, 0≤bi≤1050 \le b_i \le 10^5) — the parameters of the ii-th minion.

第一行包含一个整数 TT(1≤T≤751 \le T \le 75)—— 测试用例的数量。

每个测试用例以一行开始,该行包含两个整数 nn 和 kk(1≤k≤n≤751 \le k \le n \le 75)—— 分别表示可供召唤的小兵数量,以及 Polycarp 最多能控制的小兵数量。

接下来是 nn 行,其中第 ii 行包含两个整数 aia_i 和 bib_i(1≤ai≤1051 \le a_i \le 10^5,0≤bi≤1050 \le b_i \le 10^5)—— 表示第 ii 个小兵的参数。

输出格式

For each test case print the optimal sequence of actions as follows:

Firstly, print mm — the number of actions which Polycarp has to perform (0≤m≤2n0 \le m \le 2n). Then print mm integers o1o_1, o2o_2, ..., omo_m, where oio_i denotes the ii-th action as follows: if the ii-th action is to summon the minion xx, then oi=xo_i = x, and if the ii-th action is to destroy the minion xx, then oi=−xo_i = -x. Each minion can be summoned at most once and cannot be destroyed before being summoned (and, obviously, cannot be destroyed more than once). The number of minions in Polycarp's army should be not greater than kk after every action.

If there are multiple optimal sequences, print any of them.

对每个测试用例,按如下格式输出最优的操作序列:

首先,输出 mm —— Polycarp 需要执行的操作数量(0≤m≤2n0 \le m \le 2n)。然后输出 mm 个整数 o1o_1, o2o_2, ..., omo_m,其中 oio_i 表示第 ii 个操作:若第 ii 个操作是召唤随从 xx,则 oi=xo_i = x;若第 ii 个操作是消灭随从 xx,则 oi=−xo_i = -x。每个随从最多只能被召唤一次,且不能在被召唤前被消灭(显然也不能被消灭超过一次)。每次操作后,Polycarp 军队中的随从数量均不得超过 kk。

若存在多个最优序列,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    5 2
    5 3
    7 0
    5 0
    4 0
    10 0
    2 1
    10 100
    50 10
    5 5
    1 5
    2 4
    3 3
    4 2
    5 1

    输出#1

    4
    2 1 -1 5
    1
    2
    5
    5 4 3 2 1

说明/提示

Consider the example test.

In the first test case, Polycarp can summon the minion 22 with power level 77, then summon the minion 11, which will increase the power level of the previous minion by 33, then destroy the minion 11, and finally, summon the minion 55. After this, Polycarp will have two minions with power levels of 1010.

In the second test case, Polycarp can control only one minion, so he should choose the strongest of them and summon it.

In the third test case, Polycarp is able to summon and control all five minions.

考虑示例测试。

在第一个测试用例中,Polycarp 可以先召唤力量等级为 77 的随从 22,然后召唤随从 11,这会使前一个随从的力量等级增加 33;接着摧毁随从 11;最后召唤随从 55。经过这一系列操作后,Polycarp 将拥有两个力量等级均为 1010 的随从。

在第二个测试用例中,Polycarp 只能控制一个随从,因此他应选择其中最强的一个并将其召唤。

在第三个测试用例中,Polycarp 能够召唤并控制全部五个随从。

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

首页