시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB13713107.937%

문제

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.

  • Ascend $1$ step. This action takes $A$ seconds.
  • Jump from the current step to a step $D$ steps above, skipping the steps in between. This action takes $B$ seconds.

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 ≤ N ≤ 200\, 000$.
  • $1 ≤ Q ≤ 200\, 000$.
  • $1 ≤ D ≤ 10^{12}$.
  • $1 ≤ A ≤ 1\, 000\, 000$.
  • $1 ≤ B ≤ 1\, 000\, 000$.
  • $1 ≤ L_i ≤ R_i ≤ 10^{12}$ ($1 ≤ i ≤ N$).
  • $R_i + 1 < L_{i+1}$ ($1 ≤ i ≤ N - 1$).
  • $1 ≤ X_j ≤ 10^{12}$ ($1 ≤ j ≤ Q$).
  • Given values are all integers.

서브태스크

번호배점제한
15

$R_i ≤ 1\, 000\, 000$ ($1 ≤ i ≤ N$), $X_j ≤ 1\, 000\, 000$ ($1 ≤ j ≤ Q$).

238

$N ≤ 2\, 000$, $Q ≤ 2\, 000$.

325

$A = 1$, $B = D$.

432

No additional constraints.

예제 입력 1

3 1
4 10 35
4 5
10 12
14 14
13

예제 출력 1

120

JOI-kun can reach the $13$th step of the staircase in $120$ seconds following the steps below:

  1. Ascend from step $0$ to step $1$. This action takes $10$ seconds.
  2. Ascend from step $1$ to step $2$. This action takes $10$ seconds.
  3. Ascend from step $2$ to step $3$. This action takes $10$ seconds.
  4. Jump from step $3$ to step $7$, skipping the steps in between. This action takes $35$ seconds.
  5. Ascend from step $7$ to step $8$. This action takes $10$ seconds.
  6. Ascend from step $8$ to step $9$. This action takes $10$ seconds.
  7. Jump from step $9$ to step $13$, skipping the steps in between. This action takes $35$ seconds.

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.

예제 입력 2

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

예제 출력 2

6
11
17
22
-1
33
-1
44
-1
55

This sample input satisfies the constraints of subtasks 1, 2, and 4.

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.