| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2 초 | 1024 MB | 134 | 10 | 8 | 6.452% |
The IOI Tower is an extremely tall tower equipped with a staircase for ascending. This staircase consists of 10ドル^{100}$ steps, numbered sequentially from the bottom as step 0ドル,ドル step 1ドル,ドル and so on. JOI-kun is currently on step 0ドル$ and intends to climb the staircase. JOI-kun can ascend the staircase by taking the following 2ドル$ types of actions. Descending the staircase is not permitted.
Currently, construction is ongoing at several locations on the staircase, and steps undergoing construction cannot be stepped on. Specifically, there are $N$ ongoing constructions, and the $i$-th construction (1ドル ≤ i ≤ N$) is being carried out at steps $L_i , L_{i+1}, \dots , R_i$.
The IOI Tower has $Q$ rooms numbered from 1ドル$ to $Q$. One can enter room $j$ (1ドル ≤ j ≤ Q$) from step $X_j$ of the staircase. Therefore, JOI-kun has decided to determine whether he can reach each room and, if possible, how many seconds it will take to reach there in the minimum time.
Given the information about JOI-kun, constructions, and rooms, create a program that determines whether JOI-kun can reach step $X_j$ for each $j$ (1ドル ≤ j ≤ Q$) and, if possible, calculates the minimum time it takes.
Read the following data from the standard input.
$N$ $Q$
$D$ $A$ $B$
$L_1$ $R_1$
$L_2$ $R_2$
$\vdots$
$L_N$ $R_N$
$X_1$
$X_2$
$\vdots$
$X_Q$
Output $Q$ lines to the standard output. On the $j$-th line (1ドル ≤ j ≤ Q$), output the minimum number of seconds it takes if JOI-kun can reach step $X_j$; otherwise, output -1.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 5 | $R_i ≤ 1,円 000,円 000$ (1ドル ≤ i ≤ N$), $X_j ≤ 1,円 000,円 000$ (1ドル ≤ j ≤ Q$). |
| 2 | 38 | $N ≤ 2,円 000,ドル $Q ≤ 2,円 000$. |
| 3 | 25 | $A = 1,ドル $B = D$. |
| 4 | 32 | No additional constraints. |
3 1 4 10 35 4 5 10 12 14 14 13
120
JOI-kun can reach the 13ドル$th step of the staircase in 120ドル$ seconds following the steps below:
Since it’s not possible to reach the 13ドル$th step of the staircase in less than 120ドル$ seconds, the output is 120ドル$.
This sample input satisfies the constraints of subtasks 1, 2, and 4.
5 10 10 1 9 7 11 25 32 37 38 43 44 50 52 6 12 18 24 30 36 42 48 54 60
6 11 17 22 -1 33 -1 44 -1 55
This sample input satisfies the constraints of subtasks 1, 2, and 4.