import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int size_A = input.nextInt();
int size_B = input.nextInt();
int x = input.nextInt();
int A[] = new int[size_A];
int B[] = new int[size_B];
for(int i=0; i<size_A; i++)
A[i] = input.nextInt();
for(int i=0; i<size_B; i++)
B[i] = input.nextInt();
Arrays.sort(A);
Arrays.sort(B);
int gap = Math.abs(A[0]+B[0]-x);
loop:
for(int i=0; i<size_A; i++){
for(int j=0; j<size_B; j++){
if (A[i] + B[j]>=x){
size_B = j+1;
if(j==0) {
if (gap > A[i] + B[j] - x)
gap = A[i] + B[j] - x;
break loop;
}
else {
if(gap>Math.min(A[i] + B[j] - x, x - A[i] - B[j - 1]))
gap = Math.min(A[i] + B[j] - x, x - A[i] - B[j - 1]);
}
}
}
}
System.out.print(gap);
}
}
이렇게 해도 경우의 수가 너무 많나요??