Submission #98351

# Submission time Handle Problem Language Result Execution time Memory
98351 2019-02-22T17:56:12 Z MohamedAhmed0 Kas (COCI17_kas) C++14
100 / 100
1371 ms 395868 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) ;
    return cout<<ans/2+sum-ans<<"\n" , 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 359 ms 395640 KB Output is correct
2 Correct 330 ms 395568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 334 ms 395736 KB Output is correct
2 Correct 356 ms 395640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 325 ms 395740 KB Output is correct
2 Correct 366 ms 395644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 395668 KB Output is correct
2 Correct 357 ms 395768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 395640 KB Output is correct
2 Correct 357 ms 395640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 395624 KB Output is correct
2 Correct 342 ms 395660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 395556 KB Output is correct
2 Correct 329 ms 395692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 525 ms 395792 KB Output is correct
2 Correct 368 ms 395772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 522 ms 395640 KB Output is correct
2 Correct 538 ms 395868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 756 ms 395664 KB Output is correct
2 Correct 1371 ms 395752 KB Output is correct