You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
602 B
33 lines
602 B
#include <iostream>
|
|
|
|
using namespace std;
|
|
const int N = 15;
|
|
const int INF = 0x3f3f3f3f;
|
|
int a[N];
|
|
int n;
|
|
int cha = INF;
|
|
int res1, res2;
|
|
/*
|
|
3
|
|
200 300 110
|
|
*/
|
|
void dfs(int u, int s1, int s2) {
|
|
if (u == n) {
|
|
if (s1 < s2) swap(s1, s2);
|
|
if (s1 - s2 < cha) {
|
|
res1 = s1, res2 = s2;
|
|
cha = s1 - s2;
|
|
}
|
|
return;
|
|
}
|
|
dfs(u + 1, s1 + a[u], s2);
|
|
dfs(u + 1, s1, s2 + a[u]);
|
|
}
|
|
|
|
int main() {
|
|
cin >> n;
|
|
for (int i = 0; i < n; i++) cin >> a[i];
|
|
dfs(0, 0, 0);
|
|
printf("%d %d\n", res1, res2);
|
|
return 0;
|
|
} |