# PAT-A 真题 – 1113 Integer Set Partition

Given a set of  () positive integers, you are supposed to partition them into two disjoint sets  and  of  and  numbers, respectively. Let  and  denote the sums of all the numbers in  and , respectively. You are supposed to make the partition so that  is minimized first, and then  is maximized.

### Input Specification:

Each input file contains one test case. For each case, the first line gives an integer  (), and then  positive integers follow in the next line, separated by spaces. It is guaranteed that all the integers and their sum are less than .

### Output Specification:

For each case, print in a line two numbers:  and , separated by exactly one space.

### Sample Input 1:

10
23 8 10 99 46 2333 46 1 666 555

### Sample Output 1:

0 3611

### Sample Input 2:

13
110 79 218 69 3721 100 29 135 2 6 13 5188 85

### Sample Output 2:

1 9359

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

int main(){
int n;
cin >> n;
vector<int> num;
for(int i = 0; i < n; i++){
int _;
cin >> _;
num.push_back(_);
}
sort(num.begin(), num.end());
cout << n%2 << ' ';
int S1 = 0, S2 = 0;
for(int i = 0; i < n; i++){
if(i < n/2) S1 += num[i];
else S2 += num[i];
}
cout << abs(S1 - S2);
return 0;
}