#include<iostream> #include<algorithm> using namespace std; const int N=0x3f3f3f3f; int n,sum,k; int f[100005]; int main(){ cin>>n; for(int i=0;i<n;++i){ cin>>f[i]; } sort(f,f+n); k=f[n/2]; for(int i=0;i<n;++i){ sum+=abs(k-f[i]); } cout<<sum; return 0; }
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.
Using your 追梦算法网 universal account