# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1042907 |
2024-08-03T14:33:33 Z |
VMaksimoski008 |
Kas (COCI17_kas) |
C++17 |
|
217 ms |
392532 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int dp[505][2*maxn+5], v[505];
int main() {
int n, sum = 0;
cin >> n;
for(int i=1; i<=n; i++) cin >> v[i], sum += v[i];
for(int j=0; j<=2*maxn; j++) dp[0][j] = -1e9;
dp[0][maxn] = 0;
for(int i=1; i<=n; i++) {
for(int j=0; j<=2*maxn; j++) {
dp[i][j] = dp[i-1][j];
if(j + v[i] <= 2 * maxn) dp[i][j] = max(dp[i][j], dp[i-1][j+v[i]] + v[i]);
if(j - v[i] >= 0) dp[i][j] = max(dp[i][j], dp[i-1][j-v[i]] + v[i]);
}
}
cout << sum - dp[n][maxn] / 2 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9048 KB |
Output is correct |
2 |
Correct |
5 ms |
9048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9052 KB |
Output is correct |
2 |
Correct |
5 ms |
9052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9052 KB |
Output is correct |
2 |
Correct |
5 ms |
9660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
10840 KB |
Output is correct |
2 |
Correct |
6 ms |
11348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11356 KB |
Output is correct |
2 |
Correct |
7 ms |
11356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
28400 KB |
Output is correct |
2 |
Correct |
20 ms |
32348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
36440 KB |
Output is correct |
2 |
Correct |
23 ms |
40540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
157768 KB |
Output is correct |
2 |
Correct |
110 ms |
196728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
235840 KB |
Output is correct |
2 |
Correct |
184 ms |
314196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
353328 KB |
Output is correct |
2 |
Correct |
217 ms |
392532 KB |
Output is correct |