# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
442983 |
2021-07-09T12:45:52 Z |
zxcvbnm |
Kas (COCI17_kas) |
C++14 |
|
607 ms |
198088 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxS = 1e5 + 5;
const int INF = 1e9 + 5;
int dp[505][maxS];
vector<int> a;
int n;
int go(int k, int diff) {
if (diff >= maxS) {
return -INF;
}
if (dp[k][diff] != -1) {
return dp[k][diff];
}
int& ret = dp[k][diff];
if (k == n) {
return ret = (diff == 0 ? 0 : -INF);
}
return ret = max({go(k+1, diff), go(k+1, diff+a[k])+a[k], go(k+1, abs(diff-a[k]))+a[k]});
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
memset(dp, -1, sizeof dp);
cin >> n;
a.resize(n);
for(int i = 0; i < n; i++) {
cin >> a[i];
}
int sum = accumulate(a.begin(), a.end(), 0);
int sol = go(0, 0);
// cout << sol << "\n";
cout << (sol / 2) + (sum - (sol));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
197932 KB |
Output is correct |
2 |
Correct |
86 ms |
197884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
197956 KB |
Output is correct |
2 |
Correct |
88 ms |
197952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
197912 KB |
Output is correct |
2 |
Correct |
95 ms |
197948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
197836 KB |
Output is correct |
2 |
Correct |
86 ms |
197960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
197844 KB |
Output is correct |
2 |
Correct |
87 ms |
197924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
197928 KB |
Output is correct |
2 |
Correct |
86 ms |
197828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
197944 KB |
Output is correct |
2 |
Correct |
86 ms |
197888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
175 ms |
198088 KB |
Output is correct |
2 |
Correct |
124 ms |
197956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
214 ms |
198084 KB |
Output is correct |
2 |
Correct |
227 ms |
197976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
394 ms |
197980 KB |
Output is correct |
2 |
Correct |
607 ms |
198084 KB |
Output is correct |