LCC '25 Contest 3 S4 - Bob's Revenge
View as PDF🐧🐧 Bob the penguin 🐧🐧 has had enough 🐧. In rage, he throws his homework at you >:(
🐧 the penguin has
presents, where each present has its own weight
and height
. 🐧 puts each of these presents into his two types of processing machines; weight and height. However, since 🐧's been too lazy to fix his machine, each weight processor can only process weights
, and each height processor can only process heights
. Furthermore, each processor can only process a single present every second, and each present only needs to be processed once. 🐧 wants to know one thing: what is the least number of seconds required to process every present?
However, 🐧, being greatly unhappy with you, decides to make your life even more annoying. He provides you with shrinkifiers, each allowing you to shrink the height of a present by one. Shrinkifiers are able to shrink the same present multiple times, and you do not need to use all
shrinkifiers. Can you solve this problem?
Input Specification
The first line of input will contain three space-separated integers .
The second line of input will contain space-separated integers
, representing the weight capacity of the
weight processor.
The third line of input will contain space-separated integers
, representing the height capacity of the
height processor.
The next lines of input will contain two space-separated integers
, representing the weight and height specifications of the
present.
Output Specification
Output line, containing a single integer repersenting the least number of seconds required to process every present. If it is never achievable, output
-1
Constraints
For all subtasks,
| Marks Allocated | Bounds on |
Bounds on |
Bounds on |
Bounds on |
|---|---|---|---|---|
Sample Input 1
1 2 5 0
10000
1 3
1 1
2 3
2 5
5 4
3 4
Sample Output 1
3
Sample Explanation 1
Notice that the last presents all can only be processed by the singular weight procecssor. Therefore, it takes at least
seconds to process all of them. We have no shrinkifiers to modify the heights.
Sample Input 2
1 1 1 1
1
100
10 101
Sample Output 2
1
Sample Explanation 2
We use the shrinkifier on the only present in order to be able to process it.
Comments