#P3248. [ioi2013]robots

[ioi2013]robots

Problem Description

Marita's brother left his toys scattered on the living room floor. Luckily, Marita has designed special robots that can pick up the toys. However, she needs to determine which robot will pick up which toy.

There are TT toys, where integer W[i]W[i] represents the weight of the toy, and integer S[i]S[i] represents its volume. There are two types of robots: weak robots and small robots.

  • There are AA weak robots. Each weak robot has a weight limit X[i]X[i], meaning it can only pick up toys that have a weight strictly less than X[i]X[i], regardless of the toy's volume.
  • There are BB small robots. Each small robot has a volume limit Y[i]Y[i], meaning it can only pick up toys with a volume strictly less than Y[i]Y[i], regardless of the toy's weight.

Each robot can take 1 minute to pick up a toy and put it away. Different robots can pick up and put away different toys simultaneously.

Your task is to determine if Marita's robots can pick up all the toys, and if so, calculate the minimum amount of time required.

Input Format

  • The 1st line: AA indicates the number of weak robots, BB indicates the number of small robots, and TT indicates the number of toys;
  • The 2nd line: An array of length AA, X[0],,X[A1]X[0],\cdots,X[A-1], where X[i]X[i] represents the weight limit of the ii-th weak robot;
  • The 3rd line: An array of length BB, Y[0],,Y[B1]Y[0],\cdots,Y[B-1], where Y[i]Y[i] represents the volume limit of the ii-th small robot;
  • The next TT lines: W[i]W[i], S[i]S[i], where W[i]W[i] is the weight of the ii-th toy, and S[i]S[i] is the volume of the ii-th toy.
  • If A=0A = 0 or B=0B = 0, then the respective line (2nd or 3rd line) is empty.

Output Format

  • A single line, output the minimum time required for the robots to pick up all the toys, or output -1 if it is not possible.

样例 #1

样例输入 #1

3 2 10
6 2 9
4 7
4 6
8 5
2 3
7 9
1 8
5 1
3 3
8 7
7 6
10 5

样例输出 #1

3

样例 #2

样例输入 #2

2 1 3
2 5
2
3 1
5 3
2 2

样例输出 #2

-1

Notes

For 100%100\% of the data, 1T1061 \leq T \leq 10^6, 0A,B5×1040 \leq A,B \leq 5 \times 10^4 and 1A+B1 \leq A+B, 1X[i],Y[i],W[i],S[i]2×1091 \leq X[i],Y[i],W[i],S[i] \leq 2 \times 10^9.