#P9801. [NERC 2018] King Kog’s Reception
[NERC 2018] King Kog’s Reception
Background
Translated from Problem K of NERC 2018.
Problem Description
Some knights want to visit the King. Since all knights here are very polite, they make an appointment in advance, specifying the time when they will arrive and how long the visit will last. The knights visit the King in the order of times recorded at the reception desk, and each knight must wait until the previous knight finishes.
Unfortunately, the Princess also wants to visit the King. However, the kind Princess will not change the knights’ visiting order. Instead, she will wait until the knights have finished their visits and then visit the King. Please compute how long the Princess has to wait.
Input Format
There are lines in total.
The first line contains an integer .
Then there are lines, each starting with a character.
-
If the character is
+, it is followed by two numbers, meaning that knight will arrive at time , and the visit duration is time units. -
If the character is
-, it is followed by a number , meaning that knight temporarily cancels his appointment. -
If the character is
?, it is followed by a number , meaning that the Princess will visit at time .
Output Format
For each ?, output one line indicating how long the Princess has to wait. Note that, when the Princess visits, the appointment records of the knights include only the previous operations, and do not include those added later.
19
? 3
+ 2 2
? 3
? 4
+ 5 2
? 5
? 6
+ 1 2
? 2
? 3
? 4
? 5
? 6
? 7
? 9
- 8
? 2
? 3
? 6
0
1
0
2
1
3
2
1
2
1
0
0
2
1
1
Hint
For all testdata, it is guaranteed that , , and .
Translated by ChatGPT 5