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;
const int SM = 1e5+1, inf = 1e9;
int dp[2][SM];
int main()
{
int n;
cin >> n;
int a[1 + n];
int x = 0;
for(int i = 1; i <= n; ++i)
{
cin >> a[i];
x += a[i];
}
for(int j = 1; j <= x; j++)
dp[0][j] = -inf;
for(int i = 1; i <= n; i ++)
{
bool b = i & 1, nb = !b;
for(int j = 0; j <= x; j++)
{
dp[b][j] = dp[nb][j];
if(j >= a[i])
dp[b][j] = max(dp[b][j], dp[nb][j - a[i]]);
if(a[i] + j <= x)
dp[b][j] = max(dp[b][j], dp[nb][j + a[i]] + a[i]);
}
}
int mx = max(0, dp[n & 1][0]);
cout << mx + (x - 2 * mx) << endl;
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... |