Chef and Pairs

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
We define a function maxMatching(A, B, y), which takes two arrays of integers, A and B, an integer y, and returns an integer. The function is described as follows:
Let N be the size of array A, and M be the size of array B. Consider a bipartite graph with one side having the vertices {a_{1}, a_{2}, ..., a_{N}}, and the other side having the vertices {b_{1}, b_{2}, ..., b_{M}}. There is an edge between a_{i} and b_{j} if abs(A_{i}  B_{j}) ≤ y. The function returns the size of a maximum matching in this graph.
Now, you are given two arrays, C and D, an integer e, and asked to output the result of this procedure:
ans = maxMatching(C, D, e)
FOR x = 2*10^9..2*10^9
FOR i = 1..N
F[i] = C[i] + x
ans = max(ans, maxMatching(F, D, e))
output ans
Input
 The first line contains one integer T, denoting the number of tests. T test cases follows.
 The first line of each test case contains three integers: N  number of elements of array C, M  number of elements of array D and e.
 The second line contains N spaceseparated integers denoting elements of array C.
 The third line contains M spaceseparated integers denoting elements of array D.
Output
For each test case output the final value of "ans" as produced by the given procedure, in a new line.
Constraints
 1 ≤ T ≤ 10
 1 ≤ N, M ≤ 250
 1 ≤ C_{i}, D_{i}, e ≤ 10^{9}
Example
Input: 1 5 7 1 8 9 18 13 19 1 3 7 20 17 18 11 Output: 4
Author:  mgch 
Tags  mgch 
Date Added:  1062017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 