单词积累
disjoint 打散 拆开
思路
分成两个集合,数量之差最小,总和之差尽可能大。排序后平分即可
代码
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100003;
int n;
int num[maxn];
int main() {
cin>>n;
for (int i = 0; i < n; i++) {
cin>>num[i];
}
sort(num, num + n);
if (n % 2 == 1) cout<<1<<" ";
else cout<<0<<" ";
int ans1 = 0, ans2 = 0;
for (int i = 0; i < n / 2; i++) {
ans1 += num[i];
}
for (int i = n / 2; i < n; i++) {
ans2 += num[i];
}
cout<<ans2-ans1<<endl;
}