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;
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
const int inf = 2e9;
const int N = 1e5 + 15;
const int M = 5e2 + 15;
int n, m, a[M], ans;
bitset <N> dp1, dp2[M];
int summ = 0;
int main() {
cin >> n;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
summ += a[i];
}
dp1[0] = dp2[n+1][0] = 1;
for(int i = n; i; --i)
dp2[i] |= (dp2[i+1] << a[i]);
for(int i = 1; i <= n; ++i) {
dp1 |= (dp1 << a[i]);
bitset <N> nw = (dp1 & dp2[i+1]);
int x = nw._Find_first();
if(!x)
x = nw._Find_next(x);
if(x < N)
ans = max(ans, x + (summ - 2 * x));
}
cout << ans;
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... |