#GD0000219. Nhiệm vụ của mèo Kattis (Kattis's Quest)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nhiệm vụ của mèo Kattis (Kattis's Quest)
Kattis's Quest
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Kattis maintains a pool of game quests. Each quest costs energy and rewards gold. There are events. An add E G event inserts a new quest, and identical quests remain separate items. A query X event starts a gaming session with energy . Kattis repeatedly chooses an unfinished quest having the largest energy cost no greater than the remaining energy; ties in energy are broken by choosing the largest gold reward. The quest is removed, its energy cost is deducted and its gold added to the session total. The session ends when no quest can be completed. Print the gold earned in each query; uncompleted quests persist across sessions.
Input
- Line 1 contains , the number of events.
- Each of the next lines is either
add E G(add a quest costing energy and rewarding gold) orquery X(play a session with initial energy ). Command names are lowercase; numeric arguments are integers.
Output
Print one line for every query command, showing the total gold earned in that session. An add command produces no output.
Subtasks
- Subtask 1 (20 points): ; every event has the form
add E Gorquery X; for the corresponding parameters. - Subtask 2 (30 points): ; every event has the form
add E Gorquery X; for the corresponding parameters. - Subtask 3 (50 points): ; every event has the form
add E Gorquery X; for the corresponding parameters.
Examples
Input
9
add 8 10
add 3 25
add 5 6
query 7
query 7
add 1 9
add 2 13
query 20
query 1
Output
6
25
32
0
Explanation
Initially quests are . Query completes the energy- quest for gold, then has insufficient energy for another quest. The next query completes the energy- quest for gold. After adding and , query completes all three remaining quests, earning . Query then earns because the pool is empty.