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 a_i and the i-th New Year's gift costing b_i. 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, a_i + b_j = M (he must be fair), and where the gift pair is interesting. Tommy considers a gift pair a_i, b_j interesting if |i - j| \geq 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 (0 \leq K < N), M.

The next line of input contains N integers, separated by space, representing a_1, a_2, \dots, a_N (1 \leq a_i \leq M).

The last line of input contains N integers, separated by space, representing b_1, b_2, \dots, b_N (1 \leq b_i \leq M).

It is guaranteed that all a_i are distinct and all b_i are distinct.

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

Mark AwardedNumber of GiftsTotal PriceAdditional Constraints
3 marks1 \leq N \leq 2 \times 10^51 \leq M \leq 10^{18}K = 0
3 marks1 \leq N \leq 10^31 \leq M \leq 4 \times 10^3None
9 marks1 \leq N \leq 2 \times 10^51 \leq M \leq 10^{18}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 a_1, b_3.

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: a_1 with b_5, a_2 with b_4, a_3 with b_1, a_4 with b_2, and a_5 with b_3.


Comments

There are no comments at the moment.