# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
98349 |
2019-02-22T17:51:01 Z |
MohamedAhmed0 |
Kas (COCI17_kas) |
C++14 |
|
1538 ms |
395808 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505 ;
const int MAXSUM = 100010 ;
const int CONS = 100000 ;
int arr[MAXN] ;
int dp[MAXN][MAXSUM+CONS] ;
int n ;
int solve(int idx , int diff)
{
if(idx == n)
{
if(diff - CONS == 0)
return 0 ;
return -1e8 ;
}
int &ret = dp[idx][diff] ;
if(ret != -1)
return ret ;
ret = solve(idx+1 , diff) ;
ret = max(ret , solve(idx+1 , diff + arr[idx]) + arr[idx]) ;
ret = max(ret , solve(idx+1 , diff - arr[idx]) + arr[idx]) ;
return ret ;
}
int main()
{
memset(dp , -1 , sizeof(dp)) ;
cin>>n ;
int sum = 0 ;
for(int i = 0 ; i < n ; ++i)
{
cin>>arr[i] ;
sum += arr[i] ;
}
int ans = solve(0 , CONS) ;
//debugging
if(ans & 1)
while(1) ;
return cout<<ans/2+sum-ans<<"\n" , 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
352 ms |
395624 KB |
Output is correct |
2 |
Correct |
328 ms |
395628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
310 ms |
395700 KB |
Output is correct |
2 |
Correct |
326 ms |
395660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
350 ms |
395628 KB |
Output is correct |
2 |
Correct |
333 ms |
395692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
309 ms |
395752 KB |
Output is correct |
2 |
Correct |
315 ms |
395640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
339 ms |
395572 KB |
Output is correct |
2 |
Correct |
342 ms |
395768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
325 ms |
395620 KB |
Output is correct |
2 |
Correct |
326 ms |
395792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
325 ms |
395720 KB |
Output is correct |
2 |
Correct |
312 ms |
395632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
555 ms |
395668 KB |
Output is correct |
2 |
Correct |
408 ms |
395768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
516 ms |
395768 KB |
Output is correct |
2 |
Correct |
644 ms |
395768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
767 ms |
395808 KB |
Output is correct |
2 |
Correct |
1538 ms |
395716 KB |
Output is correct |