No.2957 Combo Deck Builder
Problem Statement
You are playing a card game. You have $N$ cards in your hand, card $1$ through card $N$, and you use them to attack an enemy.
The effect of card $i$ ( $1\leq i \leq N$ ) is as follows.
・If you have already used at least $C_i$ cards (not counting this card), it deals $X_i$ damage to the enemy.
・Otherwise, it deals $Y_i$ damage to the enemy.
You choose any number of cards from the $N$ cards and use each chosen card $1$ time, in any order. Find the maximum total damage that can be dealt.
Constraints
・ $1\leq N \leq 2\times 10^5$
・ $0\leq C_i \leq N$ ( $1\leq i \leq N$ )
・ $1\leq X_i,Y_i \leq 10^9$ ( $1\leq i \leq N$ )
・All inputs are integers.
Input
$N$ $C_1$ $X_1$ $Y_1$ $\vdots$ $C_N$ $X_N$ $Y_N$
Output
Output the answer in $1$ line.
Sample
Sample 1
Input
3 0 4 3 2 3 5 2 8 2
Output
17
The effects of the cards are as follows.
・"If at least $0$ cards have already been used, $4$ damage. Otherwise, $3$ damage." (card $1$ )
・"If at least $2$ cards have already been used, $3$ damage. Otherwise, $5$ damage." (card $2$ )
・"If at least $2$ cards have already been used, $8$ damage. Otherwise, $2$ damage." (card $3$ )
By using card 1, card 2, and card 3 in this order, you can deal $17$ damage.
・At least $0$ cards have already been used. It deals $4$ damage. (card $1$ )
・Fewer than $2$ cards have already been used. It deals $5$ damage. (card $2$ )
・At least $2$ cards have already been used. It deals $8$ damage. (card $3$ )
There is no way to deal $18$ or more damage.
Sample 2
Input
6 2 13 14 2 5 13 2 17 16 4 13 9 2 10 16 4 8 9
Output
81
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
hamamu