#P5894. Robot Toy Collection Scheduling

    ID: 19122 Type: Default 1000ms 256MiB

Robot Toy Collection Scheduling

Robot Toy Collection Scheduling

Marita's younger brother has scattered T toys on the living room floor. Each toy i has a weight \(W_i\) and a volume \(S_i\). Fortunately, Marita designed two types of robots that can help her pick up the toys:

  • Weak Robots: There are A weak robots. The j-th weak robot has a weight limit \(X_j\) and can pick up any toy whose weight is < \(X_j\) (its volume is irrelevant).
  • Small Robots: There are B small robots. The k-th small robot has a volume limit \(Y_k\) and can pick up any toy whose volume is < \(Y_k\) (its weight is irrelevant).

Each robot takes 1 minute to pick one toy. Different robots can operate simultaneously (each minute, every robot can pick at most one toy). A robot can pick up more than one toy in different minutes. Marita’s task is to determine whether all the toys can eventually be picked up by her robots, and if so, what is the minimum time needed to do so.

Note: A toy is pickable if there exists at least one robot (of either type) for which the corresponding condition holds. If any toy is not pickable by any robot, the answer is \(-1\).

inputFormat

The input is given as follows:

T A B
W[1] W[2] ... W[T]
S[1] S[2] ... S[T]
X[1] X[2] ... X[A]
Y[1] Y[2] ... Y[B]

Where:

  • T is the number of toys.
  • A is the number of weak robots and B is the number of small robots.
  • W[i] is the weight of the i-th toy.
  • S[i] is the volume of the i-th toy.
  • X[j] is the weight limit of the j-th weak robot.
  • Y[k] is the volume limit of the k-th small robot.

outputFormat

If it is possible for the robots to pick up all toys, output the minimum number of minutes required. Otherwise, output \(-1\).

sample

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