## IOI '13 P5 - Robots (Standard I/O)

View as PDF

Points: 20 (partial)
Time limit: 2.5s
Memory limit: 64M

Problem type

Marita's little brother has left toys all over the living room floor! Fortunately, Marita has developed special robots to clean up the toys. She needs your help to determine which robots should pick up which toys.

There are toys, each with an integer weight and an integer size . Robots come in two kinds: weak and small.

• There are weak robots. Each weak robot has a weight limit , and can carry any toy of weight strictly less than . The size of the toy does not matter.
• There are small robots. Each small robot has a size limit , and can carry any toy of size strictly less than . The weight of the toy does not matter.

Each of Marita's robots takes one minute to put each toy away. Different robots can put away different toys at the same time.

Your task is to determine whether Marita's robots can put all the toys away, and if so, the shortest time in which they can do this.

#### Examples

As a first example, suppose there are weak robots with weight limits , small robots with size limits , and toys as follows:

Toy number 0 1 2 3 4 5 6 7 8 9
Weight 4 8 2 7 1 5 3 8 7 10
Size 6 5 3 9 8 1 3 7 6 5

The shortest time to put all the toys away is three minutes:

Weak robot 0 Weak robot 1 Weak robot 2 Small robot 0 Small robot 1
First minute Toy 0 Toy 4 Toy 1 Toy 6 Toy 2
Second minute Toy 5 Toy 3 Toy 8
Third minute Toy 7 Toy 9

As a second example, suppose there are weak robots with weight limits , small robot with size limit , and toys as follows:

Toy number 0 1 2
Weight 3 5 2
Size 1 3 2

#### Sample Session

The following session describes the first example above:

Parameter Value
A 3
B 2
T 10
X [6, 2, 9]
Y [4, 7]
W [4, 8, 2, 7, 1, 5, 3, 8, 7, 10]
S [6, 5, 3, 9, 8, 1, 3, 7, 6, 5]
Returns 3

The following session describes the second example above:

Parameter Value
A 2
B 1
T 3
X [2, 5]
Y [2]
W [3, 5, 2]
S [1, 3, 2]
Returns -1

#### Input Specification

The input will be in the following format:

• Line will contain three integers and , respectively representing the number of weak robots, the number of small robots, and the number of toys.
• Line will contain integers, the values of , that specify the weight limit for each weak robot.
• Line will contain integers, the values of , that specify the size limit of each small robot.
• The next lines will each contain two integers and , the weight and size of each toy, respectively.

If or , then the corresponding line (line or line ) should be empty.

#### Output Specification

The output should contain one integer - the smallest number of minutes required to put all of the toys away, or if this is not possible.

#### Sample Input 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

#### Sample Output 1

3

#### Sample Input 2

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

#### Sample Output 2

-1

• and