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 = 1001;
bool dp[2][SM][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];
}
dp[0][0][0] = true;
for(int i = 1; i <= n; i ++)
{
bool b = i & 1, nb = !b;
for(int j = 0; j <= x; j++)
for(int k = 0; k <= x; k++)
{
dp[b][j][k] = dp[nb][j][k];
if(j >= a[i])
dp[b][j][k] |= dp[nb][j - a[i]][k];
if(k >= a[i])
dp[b][j][k] |= dp[nb][j][k - a[i]];
}
}
int mx = 0;
for(int i = 0; i <= x; i++)
if(dp[n & 1][i][i])
mx = i;
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... |