Untitled
unknown
c_cpp
a year ago
334 B
4
Indexable
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
int niza[n];
for(int i = 0; i < n; i++) {
cin >> niza[i];
}
sort(niza, niza + n);
long long res = 0;
int sredina = niza[n / 2];
for(int i = 0; i < n; i++) {
res += abs(niza[i] - sredina);
}
cout << res << endl;
return 0;
}
Editor is loading...
Leave a Comment