# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
873397 |
2023-11-15T02:31:54 Z |
vjudge1 |
Kas (COCI17_kas) |
C++17 |
|
86 ms |
99272 KB |
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7, inf=1e9+7;
int n, a[N], s;
int f[503][N/2];
int calc(int k, int diff)
{
if(diff>=N) return -inf;
if(f[k][diff]!=-1) return f[k][diff];
int &ret=f[k][diff];
if(k==n){
if(diff==0) return 0;
return -inf;
}
return ret=max({calc(k+1, diff), calc(k+1, diff+a[k])+a[k], calc(k+1, abs(diff-a[k]))+a[k]});
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("brocandy.inp", "r", stdin);
// freopen("brocandy.out", "w", stdout);
cin>>n;
for(int i=0; i<n; i++) cin>>a[i], s+=a[i];
memset(f, -1, sizeof(f));
int ans=calc(0, 0);
ans=ans/2+(s-ans);
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
98904 KB |
Output is correct |
2 |
Correct |
13 ms |
98908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
99088 KB |
Output is correct |
2 |
Correct |
12 ms |
98908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
98908 KB |
Output is correct |
2 |
Correct |
13 ms |
98908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
98908 KB |
Output is correct |
2 |
Correct |
12 ms |
98908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
98908 KB |
Output is correct |
2 |
Correct |
13 ms |
99048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
98908 KB |
Output is correct |
2 |
Correct |
12 ms |
99272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
98908 KB |
Output is correct |
2 |
Correct |
13 ms |
98988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
43 ms |
98904 KB |
Output is correct |
2 |
Correct |
23 ms |
99092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
98908 KB |
Output is correct |
2 |
Incorrect |
53 ms |
98904 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
99144 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |