Under construction

Still being built. Things may change

Tower

Time limit2sMemory limit1024 MB

Summary
Given blocked step ranges on a staircase, single steps costing A seconds and D-step jumps costing B seconds, find the minimum time to reach each queried step X.
Level

Medium7 of 10

Topics
Dynamic programming, Greedy, Math
Solved
No attempts yet

Problem

The IOI Tower is an extremely tall tower with a staircase for climbing. The staircase has 1010010^{100} steps, numbered from the bottom as step 00, step 11, and so on. JOI-kun is on step 00 and wants to climb the staircase. JOI-kun can ascend by taking one of the following 2 actions. Descending is not allowed.

  • Ascend 1 step. This action takes AA seconds.
  • Jump from the current step to the step DD steps above, skipping the steps in between. This action takes BB seconds.

Some steps are under construction and cannot be stepped on. There are NN constructions, and the ii-th construction covers steps Li,Li+1,…,RiL_i, L_{i+1}, \dots, R_i.

The IOI Tower has QQ rooms numbered from 11 to QQ. Room jj can be entered from step XjX_j. For each room, determine whether JOI-kun can reach step XjX_j and, if so, the minimum time needed to get there.

Input

The first line contains NN and QQ. The second line contains DD, AA, and BB. Each of the next NN lines contains LiL_i and RiR_i. Each of the next QQ lines contains XjX_j.

Output

Output QQ lines. On line jj, print the minimum number of seconds needed to reach step XjX_j. If step XjX_j is unreachable, print -1.

Constraints

  • 1≤N≤200 0001 \le N \le 200\,000
  • 1≤Q≤200 0001 \le Q \le 200\,000
  • 1≤D≤10121 \le D \le 10^{12}
  • 1≤A≤1 000 0001 \le A \le 1\,000\,000
  • 1≤B≤1 000 0001 \le B \le 1\,000\,000
  • 1≤Li≤Ri≤10121 \le L_i \le R_i \le 10^{12} (1≤i≤N1 \le i \le N)
  • Ri+1<Li+1R_i + 1 < L_{i+1} (1≤i≤N−11 \le i \le N - 1)
  • 1≤Xj≤10121 \le X_j \le 10^{12} (1≤j≤Q1 \le j \le Q)
  • All given values are integers.

Examples2

  1. Example 1

    Input
    3 1
    4 10 35
    4 5
    10 12
    14 14
    13
    
    Expected output
    120
    
  2. Example 2

    Input
    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
    
    Expected output
    6
    11
    17
    22
    -1
    33
    -1
    44
    -1
    55