#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 toys, where integer represents the weight of the toy, and integer represents its volume. There are two types of robots: weak robots and small robots.
- There are weak robots. Each weak robot has a weight limit , meaning it can only pick up toys that have a weight strictly less than , regardless of the toy's volume.
- There are small robots. Each small robot has a volume limit , meaning it can only pick up toys with a volume strictly less than , 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: indicates the number of weak robots, indicates the number of small robots, and indicates the number of toys;
- The 2nd line: An array of length , , where represents the weight limit of the -th weak robot;
- The 3rd line: An array of length , , where represents the volume limit of the -th small robot;
- The next lines: , , where is the weight of the -th toy, and is the volume of the -th toy.
- If or , 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 of the data, , and , .