Files
python/TangDou/LanQiaoBei/LanQiao13STEMA202201/4.cpp

33 lines
612 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
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 + 1) {
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 = 1; i <= n; i++) cin >> a[i];
dfs(0, 0, 0);
printf("%d %d\n", res1, res2);
return 0;
}