题目描述
blablabla
样例
blablabla
算法1
排序寻找中位数即到个点距离最小
import java.util.Scanner;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int n;
long res = 0;
Scanner in = new Scanner(System.in);
n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i) {
a[i] = in.nextInt();
}
Arrays.sort(a);
for (int i = 0; i < n; i) {
res += Math.abs(a[i] - a[n / 2]);
}
System.out.print(res);
}
}