PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题。
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include<map> #include<queue> #include<stack> #include<algorithm> using namespace std; long long a[100000+10]; long long sum=0,sum2; int n; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lld",&a[i]); sum=sum+a[i]; } sort(a+1,a+1+n); for(int i=1;i<=n/2;i=i+1) sum2=sum2+a[i]; if(n%2==0) printf("0 %lld\n",abs(2*sum2-sum)); else printf("1 %lld\n",abs(2*sum2-sum)); return 0; }