团体程序设计天梯赛 L2-017 人以群分 (25分)
题目链接:
L2-017 人以群分 (25分)
思路:
简单排个序即可
代码:
#include<bits/stdc++.h>
using namespace std;
int main() {
#ifdef MyTest
freopen("Sakura.txt", "r", stdin);
#endif
int n, ans = 0;
cin >> n;
int y = n / 2, x = n - y;
cout << "Outgoing #: " << x << '\n';
cout << "Introverted #: " << y << '\n';
vector<int> v(n);
for(int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end(), greater<int>());
for(int i = 0; i< x; i++) ans += v[i];
for(int i = x; i < n; i++) ans -=v[i];
cout << "Diff = " << ans;
return 0;
}