Problem E
Mouse Pursuit
Brandon is playing the newest idle game, Mouse Pursuit! The goal of this game is to pursue mice for cheese and glory.
In Mouse Pursuit, an event consists of pursuing a mouse. If the mouse is caught, the player might earn cheese and glory. However, if the mouse is not caught, the player might lose cheese and glory.
Given Brandon’s recent events, Brandon wants to know how much cheese and glory he earned in the last $k$ seconds.
Input
The first line of input contains a single integer, $n$ $(1 \le n \le 10^5)$.
The next $n$ lines take one of two forms:
-
CAUGHT $s$ $c$ $g$: A mouse was caught exactly $s$ seconds ago. The player gained $c$ pieces of cheese and $g$ units of glory.
-
MISS $s$ $c$ $g$: A mouse was missed exactly $s$ seconds ago. The player lost $c$ pieces of cheese and $g$ units of glory.
For all events, $0 \le c, g \le 10^6$ and $1 \le s \le 10^9$. It is guaranteed that no two events happened at exactly the same time.
The last line contains a single integer $k$. It is guaranteed that no event happened exactly $k$ seconds ago.
Output
Output two integers - the number of pieces of cheese Brandon gained in the last $k$ seconds, and the number of units of glory Brandon gained in the last $k$ seconds.
Sample Input 1 | Sample Output 1 |
---|---|
3 CAUGHT 1 6 5 MISS 4 1 2 CAUGHT 8 0 3 5 |
5 3 |