#P1899. 魔法物品
魔法物品
Description
There are two types of items: ordinary items and magic items. Ordinary items have no magical properties, while magic items have some magical attributes. Each ordinary item has a single value , but each magic item has two values: the value before identification and the value after identification (of course, is always greater than ).
To identify a magic item, you need to buy an identification scroll and use it on the magic item. After you identify one magic item, the scroll is consumed. Each identification scroll costs coins. If you do not have enough money, you cannot buy any identification scroll.
You are at a bazaar and currently hold many items. You know the value of each item and want to sell all of them. What is the maximum amount of money you can obtain?
You may assume:
- You start with no money.
- All magic items are initially unidentifed.
- As long as you have enough money, you may buy any number of identification scrolls.
Input Format
The first line contains two integers and (), denoting the number of items you own and the price of one identification scroll.
The next lines each describe one item.
For each ordinary item, the line contains a single integer ().
For each magic item, the line contains two integers and ().
Output Format
Output a single integer: the maximum amount of money you can obtain.
2 10
10
20 100
100
Hint
For of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号