#P5894. [IOI 2013] robots 机器人

[IOI 2013] robots 机器人

Problem Description

Marita’s younger brother has thrown toys all over the living room floor, making a big mess. Luckily, Marita has designed special robots that can put the toys away. However, she needs to decide which robot should pick up which toy.

There are TT toys. Integer W[i]W[i] represents the weight of the ii-th toy, and integer S[i]S[i] represents the volume of the ii-th toy. There are two kinds of robots: weak robots and small robots.

  • There are AA weak robots. Each weak robot has a weight limit X[i]X[i]. It can only pick up toys with 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]. It can only pick up toys with volume strictly less than Y[i]Y[i], regardless of the toy’s weight.

Each of Marita’s robots takes 11 minute to carry one toy away and put it in place. Different robots can carry away and put away different toys at the same time.

Your task is to determine whether Marita’s robots can put away all the toys. If yes, find the minimum time needed.

Input Format

  • Line 1: AA is the number of weak robots, BB is the number of small robots, and TT is the number of toys.

  • Line 2: An array of length AA, X[0],,X[A1]X[0],\cdots,X[A-1]. For 0iA10 \le i \le A-1, X[i]X[i] is the weight limit of the ii-th weak robot.

  • Line 3: An array of length BB, Y[0],,Y[B1]Y[0],\cdots,Y[B-1]. For 0iB10 \le i \le B-1, Y[i]Y[i] is the volume limit of the ii-th small robot.

  • The next TT lines: W[i]W[i], S[i]S[i]. For 1iT1 \le i \le T, 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 corresponding line (line 2 or line 3) is empty.

Output Format

  • One line. Output the minimum time needed for the robots to put away all toys. If it is impossible to put away all toys, output -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


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

-1

Hint

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

Translated by ChatGPT 5