// iee
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for (auto i = (a); i <= (b); ++i)
#define per(i, a, b) for (auto i = (a); i >= (b); --i)
#define fi first
#define se second
using ll = long long;
using ull = unsigned long long;
using namespace std;
void work(int);
template <class T> void read(T &x) {
x = 0; int f = 1, ch = getchar();
while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
while (isdigit(ch)) x = x * 10 + (ch - '0'), ch = getchar();
x *= f;
}
int main() {
int TT = 1; // cin >> TT;
rep(CAS, 1, TT)
work(CAS);
return 0;
}
const int N = 105, K = 2605;
int n, l, r, qian, a[N];
int S, mx, f[N][N][K], L[N][K];
void work(int CASE) {
cin >> n >> l >> r >> qian;
qian = min(qian, 2600);
rep(i, 1, n) cin >> a[i], (i >= l && i <= r) && (S += a[i]);
rep(i, l, r) per(j, l - 1, 1) rep(k, 0, qian) {
f[i][j][k] = max(f[i - 1][j][k], f[i][j + 1][k]);
if (k - (i - j) >= 0)
f[i][j][k] = max(f[i][j][k], f[i - 1][j + 1][k - (i - j)] + a[i] - a[j]);
}
rep(i, l - 1, r) rep(j, 0, qian)
L[i][j] = f[i][1][j];
memset(f, 0, sizeof f);
per(i, r, l) rep(j, r + 1, n) rep(k, 0, qian) {
f[i][j][k] = max(f[i + 1][j][k], f[i][j - 1][k]);
if (k - (j - i) >= 0)
f[i][j][k] = max(f[i][j][k], f[i + 1][j - 1][k - (j - i)] + a[i] - a[j]);
}
rep(i, l - 1, r) rep(j, 0, qian)
mx = max(mx, L[i][j] + f[i + 1][n][qian - j]);
cout << S - mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
112588 KB |
Output is correct |
2 |
Correct |
43 ms |
112716 KB |
Output is correct |
3 |
Correct |
40 ms |
112748 KB |
Output is correct |
4 |
Correct |
40 ms |
112716 KB |
Output is correct |
5 |
Correct |
39 ms |
112696 KB |
Output is correct |
6 |
Correct |
39 ms |
112640 KB |
Output is correct |
7 |
Correct |
41 ms |
112720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
112588 KB |
Output is correct |
2 |
Correct |
43 ms |
112716 KB |
Output is correct |
3 |
Correct |
40 ms |
112748 KB |
Output is correct |
4 |
Correct |
40 ms |
112716 KB |
Output is correct |
5 |
Correct |
39 ms |
112696 KB |
Output is correct |
6 |
Correct |
39 ms |
112640 KB |
Output is correct |
7 |
Correct |
41 ms |
112720 KB |
Output is correct |
8 |
Correct |
44 ms |
112676 KB |
Output is correct |
9 |
Correct |
40 ms |
112716 KB |
Output is correct |
10 |
Correct |
43 ms |
112716 KB |
Output is correct |
11 |
Correct |
45 ms |
112768 KB |
Output is correct |
12 |
Correct |
40 ms |
112796 KB |
Output is correct |
13 |
Correct |
48 ms |
112948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
112588 KB |
Output is correct |
2 |
Correct |
43 ms |
112716 KB |
Output is correct |
3 |
Correct |
40 ms |
112748 KB |
Output is correct |
4 |
Correct |
40 ms |
112716 KB |
Output is correct |
5 |
Correct |
39 ms |
112696 KB |
Output is correct |
6 |
Correct |
39 ms |
112640 KB |
Output is correct |
7 |
Correct |
41 ms |
112720 KB |
Output is correct |
8 |
Correct |
44 ms |
112676 KB |
Output is correct |
9 |
Correct |
40 ms |
112716 KB |
Output is correct |
10 |
Correct |
43 ms |
112716 KB |
Output is correct |
11 |
Correct |
45 ms |
112768 KB |
Output is correct |
12 |
Correct |
40 ms |
112796 KB |
Output is correct |
13 |
Correct |
48 ms |
112948 KB |
Output is correct |
14 |
Correct |
43 ms |
112604 KB |
Output is correct |
15 |
Correct |
41 ms |
112616 KB |
Output is correct |
16 |
Correct |
50 ms |
112676 KB |
Output is correct |
17 |
Correct |
46 ms |
112844 KB |
Output is correct |
18 |
Correct |
41 ms |
112720 KB |
Output is correct |
19 |
Correct |
53 ms |
112880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
112588 KB |
Output is correct |
2 |
Correct |
43 ms |
112716 KB |
Output is correct |
3 |
Correct |
40 ms |
112748 KB |
Output is correct |
4 |
Correct |
40 ms |
112716 KB |
Output is correct |
5 |
Correct |
39 ms |
112696 KB |
Output is correct |
6 |
Correct |
39 ms |
112640 KB |
Output is correct |
7 |
Correct |
41 ms |
112720 KB |
Output is correct |
8 |
Correct |
44 ms |
112676 KB |
Output is correct |
9 |
Correct |
40 ms |
112716 KB |
Output is correct |
10 |
Correct |
43 ms |
112716 KB |
Output is correct |
11 |
Correct |
45 ms |
112768 KB |
Output is correct |
12 |
Correct |
40 ms |
112796 KB |
Output is correct |
13 |
Correct |
48 ms |
112948 KB |
Output is correct |
14 |
Correct |
43 ms |
112604 KB |
Output is correct |
15 |
Correct |
41 ms |
112616 KB |
Output is correct |
16 |
Correct |
50 ms |
112676 KB |
Output is correct |
17 |
Correct |
46 ms |
112844 KB |
Output is correct |
18 |
Correct |
41 ms |
112720 KB |
Output is correct |
19 |
Correct |
53 ms |
112880 KB |
Output is correct |
20 |
Correct |
42 ms |
112692 KB |
Output is correct |
21 |
Correct |
42 ms |
112612 KB |
Output is correct |
22 |
Correct |
47 ms |
112668 KB |
Output is correct |
23 |
Correct |
43 ms |
112684 KB |
Output is correct |
24 |
Correct |
44 ms |
112976 KB |
Output is correct |
25 |
Correct |
54 ms |
113172 KB |
Output is correct |