-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREMONE.java
51 lines (50 loc) · 1.52 KB
/
REMONE.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.*;
import java.io.*;
class REMONE {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while(t>0)
{
t--;
int n = Integer.parseInt(br.readLine());
String[] ain = br.readLine().split(" ");
String[] bin = br.readLine().split(" ");
int[] a = new int[n+1];
int[] b = new int[n];
for (int i = 0; i < n; i++) {
a[i] = Integer.parseInt(ain[i]);
}
for (int i = 0; i < n-1; i++) {
b[i] = Integer.parseInt(bin[i]);
}
Arrays.sort(a);
Arrays.sort(b);
if (n==2) {
if(b[0]>a[1])
{
System.out.println(b[0]-a[1]);
}
else
{
System.out.println(b[0]-a[0]);
}
}
else{
if(b[0]-a[0] == b[n-2]-a[n-2])
{
System.out.println(b[0]-a[0]);
}
else{
if(b[0]-a[1] == b[n-2]-a[n-1])
{
System.out.println(b[0]-a[1]);
}
else{
System.out.println(b[0]-a[0]);
}
}
}
}
}
}