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 in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define forinc(x,a,b) for (int x=a;x<=b;x++)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define all(a) a.begin(),a.end()
#define reset(f,x) memset(f, x, sizeof(f))
#define getbit(x,i) ((x>>i)&1)
#define batbit(x,i) (x|(1ll<<i))
#define tatbit(x,i) (x&~(1<<i))
#define gg exit(0);
#define int long long
const int N = 55;
const int M = 1002;
int f[N][M][M];
int n;
int c[N];
int solve(int k, int a, int b)
{
if(f[k][a][b] != -1) return f[k][a][b];
int &ret = f[k][a][b];
if (k == n+1)
{
return ret = (a == b ? 0 : -1e9);
}
return ret = max({solve(k+1, a, b), solve(k+1, a+c[k], b)+c[k], solve(k+1, a, b+c[k])+c[k]});
}
main()
{
fasty;
cin >> n;
int sum=0;
forinc(i,1,n)
{
cin >> c[i];
sum+=c[i];
}
memset(f , -1 ,sizeof f);
int split = solve(1 , 0 , 0);
cout << (sum - split) + split/2;
}
Compilation message (stderr)
kas.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
38 | main()
| ^~~~
# | 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... |