距离和最小
#include<iostream> #include<algorithm> using namespace std; int main() { int n,place,i; cin>>n; int a[n]; for(i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); int total=0; place=a[n/2]; for(i=0;i<n;i++) { total+=abs(place-a[i]); } cout<<total<<endl; }