#P2647. 最大收益
最大收益
Description
You are given items, numbered . You may choose any subset of them in any order. The -th item has two attributes and . When you choose the -th item, you immediately gain a profit of ; however, the profits of all items chosen after this item are reduced by . Determine which items to choose and in what order to choose them so that the total profit is maximized.
Note that the reductions are cumulative. For example, if you choose item , you gain ; then if you choose item , you gain ; afterwards, if you choose item , you gain ; hence the total profit is .
Input Format
The first line contains a positive integer , the number of items.
Lines through each contain two non-negative integers and , as described above.
Output Format
Output a single line with the maximum profit.
2
5 2
3 5
6
Hint
Constraints
- 20% of the testdata satisfies , .
- 50% of the testdata satisfies , .
- 100% of the testdata satisfies , .
Sample Explanation
We can choose item to gain profit; then choose item to gain profit. The total profit is .
Translated by ChatGPT 5
京公网安备 11011102002149号