Problem E
Kattis's Quest
Kattis the Cat enjoys clearing quests on her mobile game.
Each quest has an energy consumption
-
Find the largest energy quest from the current pool of quest which is smaller or equal to
, if tied, by the largest gold reward, -
Clear the quest, removing it from current pool. Reduce energy
by of the quest, and add up the gold reward earned this session. -
Repeat steps
and with remaining amount of energy, until energy left becomes , or if there are no more quests to be cleared with remaining energy.
However, she is not sure if this strategy is optimal, and
wants your help in determining how much she has earned in each
playing session. Kattis the Cat will give a list of
-
add E G: add a copy of the quest with energy consumption
and gold reward into the pool, -
query X: using the ‘greedy’ quest clearing strategy described above, print out the total amount of gold Kattis the Cat earned in this session with energy
.
Input
The first line contains an integer
Output
For each query X command, print the amount of gold Kattis the Cat earned for that session in a new line.
Sample Input 1 | Sample Output 1 |
---|---|
9 add 8 10 add 3 25 add 5 6 query 7 query 7 add 1 9 add 2 13 query 20 query 1 |
6 25 32 0 |