#ABC195D. [ABC195D] Shipping Center

[ABC195D] Shipping Center

Score : 400400 points

Problem Statement

We have NN pieces of baggage called Baggage 11 through NN, and MM boxes called Box 11 through MM.

Baggage ii has a size of WiW_i and a value of ViV_i.

Box ii can contain a piece of baggage whose size of at most XiX_i. It cannot contain two or more pieces of baggage.

You will be given QQ queries. In each query, given two integers LL and RR, solve the following problem:

  • Problem: Out of the MM boxes, RL+1R-L+1 boxes, Box L,L+1,,RL,L+1,\ldots,R, have become unavailable. Find the maximum possible total value of a set of baggage that we can put into the remaining boxes simultaneously.

Constraints

  • 1N501 \leq N \leq 50
  • 1M501 \leq M \leq 50
  • 1Q501 \leq Q \leq 50
  • 1Wi1061 \leq W_i \leq 10^6
  • 1Vi1061 \leq V_i \leq 10^6
  • 1Xi1061 \leq X_i \leq 10^6
  • 1LRM1 \leq L \leq R \leq M
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM QQ

W1W_1 V1V_1

\vdots

WNW_N VNV_N

X1X_1 \ldots XMX_M

Query1\mathrm{Query}_1

\vdots

QueryQ\mathrm{Query}_Q

Each Query is in the following format:

LL RR

Output

Print QQ lines.

The ii-th line should contain the answer to the problem described by Queryi\mathrm{Query}_i.

3 4 3
1 9
5 3
7 8
1 8 6 9
4 4
1 4
1 3
20
0
9

In the 11-st query, only Box 44 is unavailable. By putting Baggage 11 into Box 11, Baggage 33 into Box 22, and Baggage 22 into Box 33, we can put all baggage into boxes, making the total value of baggage in boxes 2020.

In the 22-nd query, all boxes are unavailable; the answer is 00.

In the 33-rd query, only Box 44 is available. By putting Baggage 11 into Box 44, we can make the total value of baggage in boxes 99, which is the maximum possible result.