#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
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]);
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
680 KB |
Output is correct |
2 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
760 KB |
Output is correct |
2 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
79040 KB |
Output is correct |
2 |
Correct |
85 ms |
98552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
118268 KB |
Output is correct |
2 |
Correct |
237 ms |
157376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
312 ms |
176916 KB |
Output is correct |
2 |
Correct |
330 ms |
196540 KB |
Output is correct |