How much damage can you deal with two "Soulfire"s in hand? 8? Are you sure?-skyline- is playing Hearthstone, and his favorite class is Warlock. There's a special mechanism designed for cards of the Warlock class that after playing some cards from hand, one may need to discard some cards from the remaining hand randomly.
-skyline- has a hand of $n$ cards, with each card can deal some damage, but also possibly would discard some other cards from hand after playing. He is planning for a lethal turn. As a professional player of Hearthstone, he doesn't believe in his luck, so he wants to calculate that in the
worst case, what is the maximum damage he can deal using this hand(We ignore the mana costs of the cards and assume that every card can be played, if not discarded).
Formally, there are $n$ cards in -skyline-'s hand, and the $i$th card has two properties $d_i$ and $a_i$, denoting the damage it can deal and the number of cards one needs to discard after playing this card, respectively.
-skyline- can choose the order to play cards from his hand, one by one. After he chooses to play the $i$th card from his hand(after playing, this card no longer exists in his hand), he would deal $d_i$ damage to the enemy hero, then $a_i$ cards from his remaining hand are uniformly chosen at random, then discarded(If currently -skyline- has a hand of less than $a_i$ cards, then all cards in his hand would be discarded). After a card is discarded from hand, it can not be played anymore.
-skyline- wants to choose the best strategy, such that
in the worst case, he would deal the maximum number of total damage to the enemy hero. Please help -skyline- find out what this total damage is.