#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, r, K;
cin >> n >> l >> r >> K;
vector<int> v(n+1);
for(int i=1; i<=n; i++) cin >> v[i];
int sum = 0;
for(int i=l; i<=r; i++) sum += v[i];
int dpL[l][n+1][K+1], dpR[n+2][n+2][K+1];
memset(dpR, 0, sizeof(dpR));
memset(dpL, 0, sizeof(dpL));
for(int i=1; i<l; i++) {
for(int j=l; j<=r; j++) {
for(int k=0; k<=K; k++) {
dpL[i][j][k] = min(dpL[i][j][k], dpL[i-1][j][k]);
dpL[i][j][k] = min(dpL[i][j][k], dpL[i][j-1][k]);
if(j - i <= k) dpL[i][j][k] = min(dpL[i][j][k], dpL[i-1][j-1][k-j+i] + v[i] - v[j]);
}
}
}
for(int i=r; i>=l; i--) {
for(int j=n; j>=r+1; j--) {
for(int k=0; k<=K; k++) {
dpR[i][j][k] = min(dpR[i][j][k], dpR[i+1][j][k]);
dpR[i][j][k] = min(dpR[i][j][k], dpR[i][j+1][k]);
if(j - i <= k) dpR[i][j][k] = min(dpR[i][j][k], dpR[i+1][j+1][k-j+i] + v[j] - v[i]);
}
}
}
int mn = min(dpL[l-1][r][K], dpR[l][r+1][K]);
for(int i=l; i<r; i++)
for(int j=0; j<=K; j++)
mn = min(mn, dpL[l-1][i][j] + dpR[i+1][r+1][K-j]);
cout << sum + mn << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
11100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
11100 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
1372 KB |
Output is correct |
13 |
Correct |
99 ms |
155984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
11100 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
1372 KB |
Output is correct |
13 |
Correct |
99 ms |
155984 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
1884 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
2 ms |
2736 KB |
Output is correct |
18 |
Correct |
3 ms |
4188 KB |
Output is correct |
19 |
Correct |
97 ms |
155912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
11100 KB |
Output is correct |
8 |
Correct |
1 ms |
1112 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
2 ms |
3164 KB |
Output is correct |
12 |
Correct |
1 ms |
1372 KB |
Output is correct |
13 |
Correct |
99 ms |
155984 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
1884 KB |
Output is correct |
16 |
Correct |
1 ms |
860 KB |
Output is correct |
17 |
Correct |
2 ms |
2736 KB |
Output is correct |
18 |
Correct |
3 ms |
4188 KB |
Output is correct |
19 |
Correct |
97 ms |
155912 KB |
Output is correct |
20 |
Correct |
16 ms |
29276 KB |
Output is correct |
21 |
Correct |
22 ms |
40028 KB |
Output is correct |
22 |
Correct |
1 ms |
1880 KB |
Output is correct |
23 |
Runtime error |
160 ms |
262144 KB |
Execution killed with signal 9 |
24 |
Halted |
0 ms |
0 KB |
- |