-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeforce985A.java
More file actions
37 lines (25 loc) · 944 Bytes
/
Copy pathCodeforce985A.java
File metadata and controls
37 lines (25 loc) · 944 Bytes
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Codeforce985A {
public static void main(String[] args)throws Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(input.readLine());
StringTokenizer tokn = new StringTokenizer(input.readLine());
int [] values = new int[n/2];
for (int i = 0; i < n / 2; i++) {
values[i] = Integer.parseInt(tokn.nextToken());
}
Arrays.sort(values);
int count1 = 0;
int count2 = 0;
for (int i = 0, j = 1; i < n/2 ; i++, j+=2) {
count1 += Math.abs(values[i] - j);
}
for (int i = 0, j = 2; i < n/2 ; i++, j+=2) {
count2 += Math.abs(values[i] - j);
}
System.out.println(Math.min(count1, count2));
}
}