QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100

#3407. 礼物搜寻

统计

在赢得了本市最大购物商场的两张优惠券后,你迫不及待地邀请女朋友去挑选礼物。在考察了数百种纪念品、玩具和化妆品后,你最终将候选名单缩小到了 $n$ 件礼物,编号为 $1$ 到 $n$。每件礼物都有一个幸福值,用来衡量如果你为她买下这件礼物,她会有多开心。其中一些礼物是特殊的——你必须为她买下这些礼物(注意,礼物是否特殊与它的幸福值无关)。

优惠券 1 可用于购买总价格不超过 $V1$(人民币)的礼物。和大多数优惠券一样,如果总价格严格小于 $V1$,你无法获得任何退款。优惠券 2 的规则几乎相同,只是它的面值为 $V2$。优惠券必须分开使用。这意味着你不能将它们合并成一张面值为 $V1+V2$ 的超级优惠券。你必须将你选择的礼物分成两部分,一部分使用优惠券 1,另一部分使用优惠券 2。

今天是女朋友的生日。根据商场的规定,她可以免费拿走一件(仅限一件)礼物!现在的挑战是:如何让你的女朋友尽可能开心?

输入格式

最多包含 20 组测试数据。每组数据以 3 个整数 $V1, V2$ 和 $n$ ($1 \le V1 \le 500, 1 \le V2 \le 50, 1 \le n \le 300$) 开头,分别表示优惠券 1 的面值、优惠券 2 的面值以及候选礼物的数量。接下来的 $n$ 行,每行描述一件礼物,包含 3 个整数:$P, H$ 和 $S$,其中 $P$ 是价格,$H$ 是幸福值 ($1 \le P, H \le 1000$),$S=1$ 表示这是一件特殊礼物,你必须买下它(或者通过免费名额获取);否则 $S=0$。最后一组测试数据后会有 $V1=V2=n=0$,该行无需处理。

输出格式

对于每组测试数据,输出案例编号以及女朋友能获得的最大总幸福值。如果你无法完成任务,即即使使用了免费名额也无法买下所有特殊礼物,则幸福值为 -1(负的幸福值意味着她不开心)。每组测试数据的输出后请打印一个空行。

样例

样例输入 1

3 2 4 
3 10 1 
2 10 0 
5 100 0 
5 80 0 
3 2 4 
3 10 1 
2 10 0 
5 100 0 
5 80 1 
0 0 0

样例输出 1

Case 1: 120 

Case 2: 100

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.