Mock CCC '23 Contest 1 J3 - Pairing Gifts
View as PDFTommy bought gifts for his  friends, but he didn't get to give his gifts to them!
Tommy bought  Christmas gifts and 
 New Year's gifts, with the 
-th Christmas gift costing 
 and the 
-th New Year's gift costing 
. Strangely, his gifts can be mixed and matched freely.
He wants to make as many perfect bundles as possible! A perfect bundle is one in which there is exactly one Christmas gift, one New Year's gift,  (he must be fair), and where the gift pair is interesting. Tommy considers a gift pair 
 interesting if 
 (since gifts that are too close together in his list are too similar).
Unfortunately, it might not be possible to give all his friends perfect bundles. Can you figure out how many of his friends can get perfect bundles?
Input Specification
The first line contains three integers, separated by a single space: , 
 
, 
.
The next line of input contains  integers, separated by space, representing 
 
.
The last line of input contains  integers, separated by space, representing 
 
.
It is guaranteed that all  are distinct and all 
 are distinct.
The following table shows how the available 15 marks are distributed.
| Mark Awarded | Number of Gifts | Total Price | Additional Constraints | 
|---|---|---|---|
| None | |||
| None | 
Output Specification
Output a single integer, the maximum number of perfect bundles.
Sample Input 1
5 2 8
1 2 3 4 5
6 5 7 4 2
Output for Sample Input 1
1
Explanation of Output for Sample Input 1
The only possible perfect bundle he can make is .
Sample Input 2
5 1 8
1 3 5 6 2
3 2 6 5 7
Output for Sample Input 2
5
Explanation of Output for Sample Input 2
He can make five perfect bundles:  with 
, 
 with 
, 
 with 
, 
 with 
, and 
 with 
.
Comments
For anyone using python, using lists will most probably TLE.