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>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e5 + 5;
bool dp[51][1005][1005];
signed main() {
int n;
cin >> n;
ll sum = 0;
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i], sum += v[i];
dp[0][0][0] = 1;
for(int i=1; i<=n; i++) {
for(int j=0; j<=sum; j++) {
for(int k=0; k<=sum-j; k++) {
dp[i][j][k] = dp[i-1][j][k];
if(v[i] <= j && dp[i-1][j-v[i]][k]) dp[i][j][k] = 1;
if(v[i] <= k && dp[i-1][j][k-v[i]]) dp[i][j][k] = 1;
}
}
}
ll ans = 0;
for(int i=0; i<=sum; i++) if(dp[n][i][i]) ans = i + (sum - 2 * i);
cout << ans << '\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... |