# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
891705 |
2023-12-23T17:08:33 Z |
ind1v |
Holding (COCI20_holding) |
C++11 |
|
24 ms |
25180 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int K = 2505;
int n, l, r, k;
int a[N];
int fl[N][N][K], fr[N][N][K];
template<typename T>
bool minimize(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> l >> r >> k;
k = min(k, K - 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int cost = 0;
for (int i = l; i <= r; i++) {
cost += a[i];
}
for (int i = 1; i <= l - 1; i++) {
for (int j = l; j <= r; j++) {
for (int c = 0; c <= k; c++) {
minimize(fl[i][j][c], fl[i - 1][j][c]);
minimize(fl[i][j][c], fl[i][j - 1][c]);
if (c >= 1) {
minimize(fl[i][j][c], fl[i][j][c - 1]);
}
if (c >= j - i) {
minimize(fl[i][j][c], fl[i - 1][j - 1][c - j + i] - a[j] + a[i]);
}
}
}
}
for (int i = n; i >= r + 1; i--) {
for (int j = r; j >= l; j--) {
for (int c = 0; c <= k; c++) {
minimize(fr[i][j][c], fr[i + 1][j][c]);
minimize(fr[i][j][c], fr[i][j + 1][c]);
if (c >= 1) {
minimize(fr[i][j][c], fr[i][j][c - 1]);
}
if (c >= i - j) {
minimize(fr[i][j][c], fr[i + 1][j + 1][c - i + j] - a[j] + a[i]);
}
}
}
}
long long ans = cost;
ans = min(ans, (long long) cost + fl[l - 1][r][k]);
ans = min(ans, (long long) cost + fr[r + 1][l][k]);
for (int i = l; i <= r - 1; i++) {
for (int tk = 0; tk <= k; tk++) {
ans = min(ans, (long long) cost + fl[l - 1][i][tk] + fr[r + 1][i + 1][k - tk]);
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
1912 KB |
Output is correct |
13 |
Correct |
6 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
1912 KB |
Output is correct |
13 |
Correct |
6 ms |
6492 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1628 KB |
Output is correct |
17 |
Correct |
1 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
2908 KB |
Output is correct |
19 |
Correct |
6 ms |
6608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
3164 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
1912 KB |
Output is correct |
13 |
Correct |
6 ms |
6492 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1628 KB |
Output is correct |
17 |
Correct |
1 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
2908 KB |
Output is correct |
19 |
Correct |
6 ms |
6608 KB |
Output is correct |
20 |
Correct |
4 ms |
6236 KB |
Output is correct |
21 |
Correct |
2 ms |
2908 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
3 ms |
2908 KB |
Output is correct |
24 |
Correct |
6 ms |
11868 KB |
Output is correct |
25 |
Correct |
24 ms |
25180 KB |
Output is correct |