-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathp254.java
39 lines (25 loc) · 822 Bytes
/
p254.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
import java.util.Arrays;
import java.util.Scanner;
/**
* @author Rubén Saiz
*/
public class p254 {
public static void main(String[] args) {
final Scanner s = new Scanner(System.in);
int many, res;
int[] esquiadores = new int[200_001];
int[] esquis = new int[200_001];
while (true) {
many = s.nextInt();
if (many == 0) break;
for (int i = 0; i < many; i++) esquiadores[i] = s.nextInt();
for (int i = 0; i < many; i++) esquis[i] = s.nextInt();
Arrays.sort(esquiadores, 0, many);
Arrays.sort(esquis, 0, many);
res = 0;
for (int i = 0; i < many; i++)
res += Math.abs(esquiadores[i] - esquis[i]);
System.out.println( res );
}
}
}