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 pb push_back
#define f first
#define s second
#define ind(a) scanf("%d", &a)
#define inlld(a) scanf("%lld", &a)
#define ind2(a, b) scanf("%d%d", &a, &b)
#define inlld2(a, b) scanf("%lld%lld", &a, &b)
#define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
using namespace std;
const int N=1e5+5;
const int MOD=1e9+7;
typedef long long ll;
typedef long double ld;
int n, arr[505], tot;
int dp[505][100005];
int solve(int i, int j)
{
if(i==n+1 && j==0)
return 0;
if(i==n+1 || j>tot/2)
return -1e9;
if(dp[i][j]!=-1)
return dp[i][j];
return dp[i][j]=max(solve(i+1, j), max(solve(i+1, j+arr[i])+arr[i], solve(i+1, abs(j-arr[i])+max(0, arr[i]-j))));
}
int main()
{
ind(n);
for(int a=1; a<=n; a++)
{
ind(arr[a]);
tot+=arr[a];
}
for(int a=0; a<=n; a++)
for(int b=0; b<=tot; b++)
dp[a][b]=-1;
int ans=solve(1,0);
ans+=tot-2*ans;
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
kas.cpp: In function 'int main()':
kas.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ind(a) scanf("%d", &a)
~~~~~^~~~~~~~~~
kas.cpp:36:5: note: in expansion of macro 'ind'
ind(n);
^~~
kas.cpp:5:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
#define ind(a) scanf("%d", &a)
~~~~~^~~~~~~~~~
kas.cpp:39:9: note: in expansion of macro 'ind'
ind(arr[a]);
^~~
# | 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... |