# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
959584 |
2024-04-08T13:19:21 Z |
Beerus13 |
Kas (COCI17_kas) |
C++14 |
|
110 ms |
1244 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
bool maximize(int &a, int b) {
if(a >= b) return true;
a = b;
return false;
}
int n;
int dp[2][N];
void solve() {
cin >> n;
int cur = 0;
memset(dp[cur], -0x3f, sizeof(dp[cur]));
dp[cur][0] = 0;
int sum = 0;
for(int i = 1, x; i <= n; ++i) {
cin >> x; sum += x;
cur ^= 1;
memset(dp[cur], -0x3f, sizeof(dp[cur]));
for(int diff = 0; diff < N; ++diff) {
maximize(dp[cur][diff], dp[cur ^ 1][diff]);
if(diff + x < N) maximize(dp[cur][diff + x], dp[cur ^ 1][diff] + x);
if(diff >= x) maximize(dp[cur][diff - x], dp[cur ^ 1][diff]);
if(x >= diff) maximize(dp[cur][x - diff], dp[cur ^ 1][diff] + x - diff);
}
}
cout << sum - dp[cur][0] << '\n';
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
4 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
4 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1116 KB |
Output is correct |
2 |
Correct |
3 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1116 KB |
Output is correct |
2 |
Correct |
8 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1116 KB |
Output is correct |
2 |
Correct |
13 ms |
1244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
1116 KB |
Output is correct |
2 |
Correct |
56 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
1116 KB |
Output is correct |
2 |
Correct |
78 ms |
1220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
1216 KB |
Output is correct |
2 |
Correct |
110 ms |
1220 KB |
Output is correct |