# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98350 | 2019-02-22T17:55:16 Z | MohamedAhmed0 | Kas (COCI17_kas) | C++14 | 1531 ms | 395900 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)) ; scanf("%d" , &n) ; int sum = 0 ; for(int i = 0 ; i < n ; ++i) { scanf("%d" , &arr[i]) ; sum += arr[i] ; } int ans = solve(0 , CONS) ; return printf("%d" , ans/2+sum-ans) , 0 ; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 330 ms | 395724 KB | Output is correct |
2 | Correct | 357 ms | 395656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 334 ms | 395672 KB | Output is correct |
2 | Correct | 344 ms | 395624 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 344 ms | 395648 KB | Output is correct |
2 | Correct | 368 ms | 395772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 353 ms | 395628 KB | Output is correct |
2 | Correct | 347 ms | 395784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 372 ms | 395724 KB | Output is correct |
2 | Correct | 339 ms | 395640 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 355 ms | 395900 KB | Output is correct |
2 | Correct | 364 ms | 395768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 334 ms | 395792 KB | Output is correct |
2 | Correct | 351 ms | 395784 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 535 ms | 395760 KB | Output is correct |
2 | Correct | 399 ms | 395708 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 627 ms | 395600 KB | Output is correct |
2 | Correct | 582 ms | 395716 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 850 ms | 395768 KB | Output is correct |
2 | Correct | 1531 ms | 395736 KB | Output is correct |