Mock CCC '23 Contest 1 J3 - Pairing Gifts

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 1.0s
Memory limit: 512M

Author:
Problem type

Tommy bought gifts for his N friends, but he didn't get to give his gifts to them!

Tommy bought N Christmas gifts and N New Year's gifts, with the i-th Christmas gift costing ai and the i-th New Year's gift costing bi. 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, ai+bj=M (he must be fair), and where the gift pair is interesting. Tommy considers a gift pair ai,bj interesting if |ij|K (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: N, K (0K<N), M.

The next line of input contains N integers, separated by space, representing a1,a2,,aN (1aiM).

The last line of input contains N integers, separated by space, representing b1,b2,,bN (1biM).

It is guaranteed that all ai are distinct and all bi are distinct.

The following table shows how the available 15 marks are distributed.

Mark AwardedNumber of GiftsTotal PriceAdditional Constraints
3 marks1N2×1051M1018K=0
3 marks1N1031M4×103None
9 marks1N2×1051M1018None

Output Specification

Output a single integer, the maximum number of perfect bundles.

Sample Input 1

Copy
5 2 8
1 2 3 4 5
6 5 7 4 2

Output for Sample Input 1

Copy
1

Explanation of Output for Sample Input 1

The only possible perfect bundle he can make is a1,b3.

Sample Input 2

Copy
5 1 8
1 3 5 6 2
3 2 6 5 7

Output for Sample Input 2

Copy
5

Explanation of Output for Sample Input 2

He can make five perfect bundles: a1 with b5, a2 with b4, a3 with b1, a4 with b2, and a5 with b3.


Comments


  • 1
    Compro72  commented 60 days ago

    For anyone using python, using lists will most probably TLE.