货仓选址

#include <iostream>
#include <algorithm>
using namespace std;
const int N=10010;
typedef long long LL;
int a[N];
int n;
int main()
{
cin>>n;
LL res=0;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for(int i=0;i<n;i++) res+=abs(a[i]-a[n/2]);//abs()函数用来求整数的绝对值
cout<<res<<endl;
}

posted @ 2022-03-17 23:11  小白QIU  阅读(25)  评论(1)    收藏  举报