You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
325 B

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, res;
int a[N];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n); // 注意下标从0开始
for (int i = 0; i < n; i++) res += abs(a[i] - a[n / 2]);
printf("%d", res);
return 0;
}