#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[501][50001];
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 |
504 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 |
504 KB |
Output is correct |
2 |
Incorrect |
2 ms |
380 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
376 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 |
632 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 |
90 ms |
39904 KB |
Output is correct |
2 |
Correct |
64 ms |
49656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
59488 KB |
Output is correct |
2 |
Correct |
181 ms |
78968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
88856 KB |
Output is correct |
2 |
Runtime error |
195 ms |
196596 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |