QOJ.ac

QOJ

実行時間制限: 5 s メモリ制限: 256 MB 満点: 100

#11347. 挑选木棍

統計

很久很久以前,曹操给他的军队下了一道名为“鸡肋”的特殊命令。没人明白他的意思,大家都感到非常恐慌。然而,曹操本人却对这个有趣的想法感到非常自豪,并乐在其中。

杨修,曹操最聪明的谋士之一,理解了这道命令。他没有把这个秘密藏在心里,而是告诉了全军。曹操对他的聪明才智感到非常愤怒,想要惩罚杨修。但是,怎么能因为一个人聪明就惩罚他呢?看着鸡肋,他终于想出了一个惩罚杨修的新主意。

他告诉杨修,作为解读这道特殊命令的奖赏,他可以从桌子上尽可能多地拿走金条。但他只能用一根棍子作为容器。

形式上,我们可以把容器棍看作一个长度为 $L$ 的线段。金条也可以看作线段。这里有许多长度为 $a_i$、价值为 $v_i$ 的金条。杨修需要把这些金条放在容器线段上。金条之间不允许重叠。幸运的是,杨修想出了一个好主意。在容器的两侧,他可以让金条的一部分伸出容器外,只要每根金条的重心仍然在容器内即可。这可以帮助他获得更多价值更高的金条。

结果,杨修拿走了太多的金条,这让曹操更加愤怒。曹操在杨修回家之前就杀了他。所以没人知道杨修在容器里放了多少金条。

你能通过找出杨修所能拿到的金条的最大价值来解开这个谜团吗?

输入格式

第一行输入包含测试用例的数量 $T(1 \le T \le 100)$。接下来是 $T$ 个测试用例。 每个测试用例以两个整数 $N(1 \le N \le 1000)$ 和 $L(1 \le L \le 2000)$ 开头,分别代表金条的数量和容器棍的长度。接下来有 $N$ 行,每行包含两个整数 $a_i(1 \le a_i \le 2000)$ 和 $v_i(1 \le v_i \le 10^9)$,分别代表第 $i$ 根金条的长度和价值。

输出格式

对于每个测试用例,输出一行 “Case #x: y”,其中 $x$ 是测试用例编号(从 1 开始),$y$ 是杨修所能拿到的金条的最大价值。

样例

输入 1

4
3 7
4 1
2 1
8 1
3 7
4 2
2 1
8 4
3 5
4 1
2 2
8 9
1 1
10 3

输出 1

Case #1: 2
Case #2: 6
Case #3: 11
Case #4: 3

说明

在第三个样例中,假设容器放置在 $x$ 轴的 $0$ 到 $5$ 之间。杨修可以将第二根金条的重心放在 $0$ 处,将第三根金条的重心放在 $5$ 处,这样它们都不会掉落,他可以获得总计 $2 + 9 = 11$ 的价值。在第四个样例中,杨修只需将唯一的金条重心放在 $[0, 1]$ 之间的任意位置,即可获得 $3$ 的价值。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.