Under construction

Still being built. Things may change

Walls

Time limit3sMemory limit256 MB

Summary
Each wall must cover every laser column P_j in attack order, and the task asks for the fewest unit moves needed per wall.
Level

Hard8 of 10

Topics
Dynamic programming, Greedy
Solved
No attempts yet

Problem

JOI released a TV game, and you got a copy. It is well made, and you have played it every day for fun.

One day, a stage nicknamed 'Laser' appeared among the gamers. It is extremely hard, and even excellent players clear it only with very low probability. After many attempts, you realized that a very fast decision might clear it, and you wondered whether a program could handle it.

The Laser stage is a field with N walls. The field is a rectangle divided into 1×11 \times 1 square cells. Each cell is written as (x,y)(x, y) with integers x,y≥0x, y \ge 0. (0,0)(0, 0) is the bottom-left cell, and (x,y)(x, y) is the cell reached from (0,0)(0, 0) by moving xx cells right and yy cells up.

When the stage starts, an enemy appears and attacks. There are M attacks in order. In the jj-th attack, the enemy fires a laser straight from cell (Pj,N+1)(P_j, N+1) down to cell (Pj,0)(P_j, 0).

Each wall lies on consecutive cells with the same y coordinate. Wall ii (1≤i≤N1 \le i \le N) is a rectangle of width Bi−Ai+1B_i - A_i + 1 and height 1. At the start, wall ii occupies the cells from (Ai,i)(A_i, i) to (Bi,i)(B_i, i). Before the first attack and between attacks, you may move the walls left or right any number of times. One move shifts one wall one cell to the right or one cell to the left.

A laser becomes weaker when it hits a wall. You want to minimize the laser power by moving the walls so that every laser hits every wall. You also want to make as few wall moves as possible.

The initial position of each wall and the position of each enemy attack are given. When every laser hits every wall, find the minimum number of moves for each wall.

Input

The first line contains integers N and M, separated by a space. There are N walls, and the enemy attacks M times.

Each of the next N lines contains integers AiA_i and BiB_i, separated by a space. At the start, wall ii is placed from cell (Ai,i)(A_i, i) to cell (Bi,i)(B_i, i).

Each of the next M lines contains an integer PjP_j. In the jj-th attack, the enemy fires a laser from cell (Pj,N+1)(P_j, N+1) to cell (Pj,0)(P_j, 0).

Output

Print N lines. On the ii-th line, print the minimum number of moves for wall ii.

Constraints

1≤N≤2000001 \le N \le 200000

1≤M≤2000001 \le M \le 200000

0≤Ai≤Bi≤10000000000 \le A_i \le B_i \le 1000000000 (1≤i≤N1 \le i \le N)

0≤Pj≤10000000000 \le P_j \le 1000000000 (1≤j≤M1 \le j \le M)

Examples2

  1. Example 1

    Input
    4 4
    0 3
    4 4
    2 7
    8 11
    6
    4
    3
    8
    
    Expected output
    5
    10
    1
    7
    
  2. Example 2

    Input
    7 11
    12 39
    22 23
    5 38
    6 47
    10 43
    0 50
    18 46
    38
    19
    15
    1
    12
    29
    29
    0
    6
    40
    6
    
    Expected output
    34
    178
    13
    6
    18
    0
    36