L2-017 人以群分 (25 分)

水题。

const int N=1e5+10;
int a[N];
int n;

int main()
{
    cin>>n;

    for(int i=0;i<n;i++) cin>>a[i];

    sort(a,a+n);

    int res=0;
    for(int i=0;i<n/2;i++)
        res+=a[n-1-i]-a[i];
    if(n & 1) res+=a[n/2];

    cout<<"Outgoing #: "<<n/2+(n&1)<<endl;
    cout<<"Introverted #: "<<n/2<<endl;
    cout<<"Diff = "<<res<<endl;

    //system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14682426.html