#abc312f. F - Cans and Openers
F - Cans and Openers
Score : points
问题描述
有 件物品。
其中每一件是易拉罐、普通罐头或开罐器之一。
第 个物品由一个整数对 描述如下:
- 如果 ,则第 个物品是一个易拉罐;如果你获取它,你会得到幸福度为 。
- 如果 ,则第 个物品是一个普通罐头;如果你获取它并用开罐器打开它,你会得到幸福度为 。
- 如果 ,则第 个物品是一个开罐器;它可以最多用来打开 个罐头。
在 件物品中选取 件,求能获得的最大总幸福度。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
There are items.
Each of these is one of a pull-tab can, a regular can, or a can opener.
The -th item is described by an integer pair as follows:
- If , the -th item is a pull-tab can; if you obtain it, you get a happiness of .
- If , the -th item is a regular can; if you obtain it and use a can opener against it, you get a happiness of .
- If , the -th item is a can opener; it can be used against at most cans.
Find the maximum total happiness that you get by obtaining items out of .
Constraints
- is , , or .
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer as an integer.
Sample Input 1
8 4
0 6
0 6
1 3
1 5
1 15
2 1
2 10
2 100
Sample Output 1
27
If you obtain the -st, -nd, -th, and -th items, and use the -th item (a can opener) against the -th item, you will get a happiness of .
There are no ways to obtain items to get a happiness of or greater, but you can still get a happiness of by obtaining the -th or -th items instead of the -th in the combination above.
Sample Input 2
5 5
1 5
1 5
1 5
1 5
1 5
Sample Output 2
0
Sample Input 3
12 6
2 2
0 1
0 9
1 3
1 5
1 3
0 4
2 1
1 8
2 1
0 1
0 4
Sample Output 3
30
update @ 2024/3/10 08:54:03