#P15497. [ICPC 2025 APC] Hold the Star

[ICPC 2025 APC] Hold the Star

Description

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 (y1y - 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 sxs_x staracips. The values of s1,s2,,sms_1, s_2, \ldots, 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 rir_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 ljl_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.

Input Format

The first line of input contains three integers nn, mm, and qq (1n1091 \leq n \leq 10^9; 1m1000001 \leq m \leq 100\,000; 1q1000001 \leq q \leq 100\,000). The ii-th of the next mm lines contains two integers rir_i and sis_i (1rin1 \leq r_i \leq n; 1si1091 \leq s_i \leq 10^9). The jj-th of the next qq lines contains an integer ljl_j (1ljn1 \leq l_j \leq n).

Output Format

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

6 5 4
1 7
3 2
2 3
5 3
2 5
1
2
5
6
5
0
8
14

Hint

Explanation for the sample input/output #1

You can win the first level by spending 55 staracips by doing the following actions:

  1. Character 55 moves from room 22 to room 11. This action costs 55 staracips.
  2. Character 55 picks the star up.

You can win the second level by spending 00 staracips by doing the following actions:

  1. Character 55 picks the star up.

You can win the third level by spending 88 staracips by doing the following actions:

  1. Character 44 picks the star up.
  2. Character 44 moves from room 55 to room 44. This action costs 33 staracips.
  3. Character 44 moves from room 44 to room 33. This action costs 33 staracips.
  4. Character 44 puts the star down.
  5. Character 22 picks the star up.
  6. Character 22 moves from room 33 to room 22. This action costs 22 staracips.
  7. Character 22 puts the star down.
  8. Character 55 picks the star up.

You can win the fourth level by spending 1414 staracips by doing the following actions:

  1. Character 22 moves from room 33 to room 44, then to room 55, then to room 66. These actions cost 3×2=63 \times 2 = 6 staracips in total.
  2. Character 22 picks the star up.
  3. Character 22 moves from room 66 to room 55, then to room 44, then to room 33, then to room 22. These actions cost 4×2=84 \times 2 = 8 staracips in total.
  4. Character 22 puts the star down.
  5. Character 55 picks the star up.