| 2024 ICPC ShaanXi Provincial Contest |
|---|
| Finished |
Recently, Shirost has been addicted to a game called Lethal Company.
In the game, players will act as contract workers for the company, collecting valuable waste from abandoned industrial planets. In the process of exploration, Shirost will encounter a monster called Coil-Head, which will move extremely rapidly when nobody is watching it, but will remain stationary when someone is watching it. As soon as approached by Coil-Head, workers will be killed immediately .
Now Shirost is standing at the intersection of $$$n$$$ infinitely long passages. He knows there will be $$$m$$$ Coil-Heads, appearing in the $$$x_i$$$ th passage at the $$$t_i$$$ th moment, $$$y_i$$$ meters away from him.
For each moment $$$j$$$, the following three events will occur in order:
Shirost wants to know the latest moment that he is alive. In other word, If Shirost is dead at the latest at the $$$j$$$ th moment, then you should output $$$j-1$$$. If he won't die, please output $$$-1$$$.
The first line contains three integers $$$n$$$, $$$m$$$, $$$k$$$ ($$$1 \leq n \leq 5 \times 10^5, 1 \leq m \leq 5 \times 10^5, 1 \leq k \leq 10^{18}$$$), separated by spaces, representing the number of passages, the number of Coil-Heads, the distance that the Coil-Heads moves at each moment.
The next $$$m$$$ lines each contain three integers $$$t_i$$$, $$$x_i$$$, $$$y_i$$$ ($$$1 \leq t_i \leq 10^{18}, 1 \leq x_i \leq n, 1 \leq y_i \leq 10^{18}$$$), separated by spaces, representing the moment, the passage and the distance from Shirost when Coil-Head appears.
Output a single integer on a single line, representing the latest moment of Shirost that he is alive. If he won't die, please output $$$-1$$$.
2 3 21 1 62 2 73 1 8
6
114514 6 19198101 1 11 1 91 4 11 5 91 1 81 4 10
0
Shirost can act as follows:
| moment | passage watched | $$$1$$$st Coil-Head distance | $$$2$$$nd Coil-Head distance | $$$3$$$rd Coil-Head distance |
| 1 | 1 | 6 | ||
| 2 | 1 | 6 | 5 | |
| 3 | 2 | 4 | 5 | 6 |
| 4 | 1 | 4 | 3 | 6 |
| 5 | 2 | 2 | 3 | 4 |
| 6 | 1 | 2 | 1 | 4 |
At the $$$7$$$ th moment, no matter which passage Shirost watches, he will be killed by Coil-Head at this moment. So the answer is $$$6$$$.
| Name |
|---|


