#P15743. [JAG 2024 Summer Camp #3] Tower Defense

[JAG 2024 Summer Camp #3] Tower Defense

题目描述

There are M+1M + 1 cells labeled from 00 to MM arranged in sequence. Cell 00 contains a base, and cell MM contains a monster with health HH. There are NN soldiers deployed near the cells. The attack range of soldier ii is from cell LiL_i to RiR_i (i.e., cells Li,Li+1,,RiL_i, L_i + 1, \ldots, R_i).

Each turn, both the monster and the soldiers perform the following actions in order (first the monster, then the soldiers):

  • Monster: If the monster's health is 11 or more and it is not in cell 00, it moves one cell closer to the base (i.e., it moves to the cell with a number 11 smaller).
  • Soldiers: Any soldier whose attack range includes the cell where the monster is currently located attacks the monster and reduces its health by 11.

If the monster's health drops to 00 or below before it reaches cell 00, the monster dies in that cell, the defense is successful, and the game ends. If the monster reaches cell 00 without its health dropping to 00 or below, the defense fails and the game ends.

Determine whether the defense will succeed, and if so, find the number of the cell where the monster will die.

输入格式

The input consists of a single test case of the following format.

$$\begin{aligned} &N \ M \ H \\ &L_1 \ R_1 \\ &\vdots \\ &L_N \ R_N \end{aligned} $$

The first line contains three integers, NN, MM, and HH, representing the number of soldiers, the number of cells, and the monster's health, respectively. NN is between 11 and 100,000100,000 (both inclusive). MM is between 22 and 10610^6 (both inclusive). HH is between 11 and 101110^{11} (both inclusive).

The next NN lines each contain two integers, LiL_i and RiR_i, which represent the attack range interval of the ii-th soldier. Both LiL_i and RiR_i are between 11 and M1M - 1 (both inclusive). It is guaranteed that LiL_i is less than or equal to RiR_i.

输出格式

Output a single integer, the number of the cell where the monster will die if the defense is successful; otherwise, output 1-1.

2 5 3
2 4
3 4
3
4 5 10
1 2
2 4
4 4
3 4
-1