# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
245121 |
2020-07-05T14:06:50 Z |
Vladikus004 |
Kas (COCI17_kas) |
C++14 |
|
294 ms |
130680 KB |
#include <bits/stdc++.h>
#define inf 2e9
#define int long long
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
const int N = 505, MAX = 100000 + 5;
int n, a[N], dp[N][MAX/2], was[N][MAX/2], sum;
int get_ans(int ind, int diff){
if (diff > sum / 2)
return -inf;
if (was[ind][diff]) return dp[ind][diff];
if (ind == n){
if (diff == 0) return 0;
return -inf;
}
was[ind][diff] = 1;
dp[ind][diff] = max(get_ans(ind + 1, diff),
max(get_ans(ind + 1, diff + a[ind]) + a[ind],
get_ans(ind + 1, abs(diff - a[ind])) + max(0LL,a[ind]-diff)));
return dp[ind][diff];
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
int ans = get_ans(0, 0);
// cout << ans << "\n";
cout << ans + sum - 2 * ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
768 KB |
Output is correct |
2 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1024 KB |
Output is correct |
2 |
Correct |
5 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
34424 KB |
Output is correct |
2 |
Correct |
26 ms |
13824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
41956 KB |
Output is correct |
2 |
Correct |
170 ms |
80480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
287 ms |
130680 KB |
Output is correct |
2 |
Correct |
294 ms |
130680 KB |
Output is correct |