Hold the Star

시간 제한2초메모리 제한2048 MB

요약
각 캐릭터의 시작 방과 이동 비용이 주어질 때, 별의 시작 방마다 캐릭터 m이 별을 들도록 만드는 최소 비용을 구한다.
난이도

어려움10점 중 9점

유형
최단 경로, 동적 계획법, 그리디, 구현
정답자
아직 제출이 없습니다

문제

You are playing a computer game with nn rooms, mm characters, and one star. The rooms are arranged from left to right and numbered from 11 to nn in that order. The characters are numbered from 11 to mm. At any time, each character is in one of the rooms and the star is either in one of the rooms or held by one of the characters. The objective of the game is for the star to be held by character mm.

You can play the game by performing several actions. Each action costs a certain amount of staracips (the unit of currency in the game), possibly zero. In each action, you choose a character xx (let room yy be the room the character is currently in) and command the character to do either of the following:

  • Move to one of the adjacent rooms (y−1y − 1 or y+1y + 1), if such a room exists. If character xx is holding the star, then the character continues to hold the star. This action costs s_xs\_x staracips. The values of s_1,s_2,…,s_ms\_1, s\_2, \dots , s\_m are given.
  • Pick the star up and hold it, if the star is currently in room yy and is not held by any character. This action costs 00 staracips.
  • Put the star down and release it, if the star is currently held by character xx. The star then falls to room yy. This action costs 00 staracips.

The game contains qq levels, numbered from 11 to qq. In all levels, each character ii is initially in room r_ir\_i and character mm must hold the star to win the level. The only difference between the levels is that, in each level jj, the star is initially in room l_jl\_j.

For each level, you want to compute the minimum total staracips you have to spend to win the level. Note that you don’t have to minimize the number of actions.

입력

The first line of input contains three integers nn, mm, and qq (1≤n≤1091 ≤ n ≤ 10^9; 1≤m≤100,0001 ≤ m ≤ 100\\, 000; 1≤q≤100,0001 ≤ q ≤ 100\\, 000). The ii-th of the next mm lines contains two integers r_ir\_i and s_is\_i (1≤r_i≤n1 ≤ r\_i ≤ n; 1≤s_i≤1091 ≤ s\_i ≤ 10^9). The jj-th of the next qq lines contains an integer l_jl\_j (1≤l_j≤n1 ≤ l\_j ≤ n).

출력

For each level in order, output the minimum total staracips you have to spend to win the level.

예제1

  1. 예제 1

    입력
    6 5 4
    1 7
    3 2
    2 3
    5 3
    2 5
    1
    2
    5
    6
    
    예상 출력
    5
    0
    8
    14