This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
assert(n <= 13);
int mx = accumulate(a.begin(), a.end(), 0);
int big_sum = 0;
for(int mask = 0; mask < (1 << n); mask++) {
vector<int> b;
int curr = 0;
for(int i = 0; i < n; i++) {
if (mask & (1 << i)) {
b.push_back(a[i]);
} else {
curr += a[i];
}
}
int m = b.size();
int k = accumulate(b.begin(), b.end(), 0);
if (k % 2 || big_sum > k/2) continue;
for(int mask2 = 0; mask2 < (1 << m); mask2++) {
int sum1 = 0, sum2 = 0;
for(int i = 0; i < m; i++) {
if (mask2 & (1 << i)) {
sum1 += b[i];
} else {
sum2 += b[i];
}
}
if (sum1 == sum2) {
mx = sum1 + curr;
break;
}
}
}
cout << mx << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |