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;
map<array<int, 4>, bool> done;
const int MxN = 220;
int n, answer;
int a[MxN];
void rec(int state, int kang, int pun, int remain){
if(done[{state, kang, pun, remain}]){
return ;
}
done[{state, kang, pun, remain}] = true;
if(state == n + 1){
if(kang == pun && kang != 0){
answer = max(answer, kang);
}
return ;
}
rec(state + 1, kang + a[state], pun, remain);
rec(state + 1, kang, pun + a[state], remain);
rec(state + 1, kang, pun, remain + a[state]);
}
int main() {
cin.tie(nullptr)->ios::sync_with_stdio(false);
int q = 1;
//cin >> q;
while(q--){
done.clear();
cin >> n;
int all = 0;
for(int i=1; i<=n; ++i){
cin >> a[i];
all += a[i];
}
answer = 0;
rec(1, 0, 0, 0);
cout << answer + (all - answer * 2) << "\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... |