标签:lse main int namespace cin ons include problem 题目
链接
给一堆数,分成两堆,要求两堆数目差值最小,其次追求两堆的差值尽量大
#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn = 1e5+10;
int a[maxn];
int main(){
cin>>n;
int s1 = 0, s2 = 0;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++){
if(i<n/2) s1+=a[i];
else s2+=a[i];
}
if(n%2==0){
printf("0 ");
}
else{
printf("1 ");
}
printf("%d\n",abs(s2-s1));
}
PAT A1113 Integer Set Partition [模拟]
标签:lse main int namespace cin ons include problem 题目
原文地址:https://www.cnblogs.com/doragd/p/11461239.html