Ali Baba is hidden in the cave of the treasure, watching how the forty thieves leave and take away jewels all the time. When the thieves will depart, Ali Baba will fill his bag with the most valuable jewels, but he will have to make it quickly, so that they cannot catch him. Therefore, at every moment he wants to know which are the jewels that he will have to take when he has the opportunity. Help him!
Input start with
,
the number of jewels that fit in the bag. Follow several actions of the
thieves, one per line: If they leave a jewel, there is the word
“leave” followed by its value. If they take a jewel, there
is the word “take” followed by its value. The values of the
jewels are natural numbers, all different.
Print a line for each action of the thieves, with the maximum value of the jewels that Ali Baba could take if the thieves left at that moment.
Author: Unknown
Translator: Carlos Molina
Generation: 2026-01-25T11:16:11.897Z
© Jutge.org, 2006–2026.
https://jutge.org