#include "bits/stdc++.h"
using namespace std;
const int MXN = 105;
int val[MXN];
const int MXK = 5005;
int dp[MXN][MXN][MXK];
int n, l, r, k;
int mincost(int pos, int at, int left_to_spend) {
if (at == r + 1) {
return (left_to_spend < 0 ? INT_MAX : 0);
}
if (pos >= n || left_to_spend < 0) {
return INT_MAX;
}
if (dp[pos][at][left_to_spend] != -1) return dp[pos][at][left_to_spend];
int take_cost = abs(pos - at);
int mn = INT_MAX;
if (left_to_spend >= take_cost) {
int t = mincost(pos+1, at+1, left_to_spend - take_cost);
if (t != INT_MAX) {
mn = min(mn, val[pos] + t);
}
}
int f = mincost(pos+1, at, left_to_spend);
mn = min(mn, f);
return dp[pos][at][left_to_spend] = mn;
}
int main() {
for (int i=0; i<MXN; i++) {
for (int j=0; j<MXN; j++) {
for (int k=0; k<MXK; k++) {
dp[i][j][k] = -1;
}
}
}
cin >> n >> l >> r >> k;
l--; r--;
k = min(k, 5000);
for (int i=0; i<n; i++) cin >> val[i];
cout << mincost(0, l, k) << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1506 ms |
216312 KB |
Output is correct |
2 |
Correct |
137 ms |
216312 KB |
Output is correct |
3 |
Correct |
127 ms |
216312 KB |
Output is correct |
4 |
Correct |
130 ms |
216288 KB |
Output is correct |
5 |
Correct |
130 ms |
216312 KB |
Output is correct |
6 |
Correct |
117 ms |
216312 KB |
Output is correct |
7 |
Correct |
122 ms |
216312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1506 ms |
216312 KB |
Output is correct |
2 |
Correct |
137 ms |
216312 KB |
Output is correct |
3 |
Correct |
127 ms |
216312 KB |
Output is correct |
4 |
Correct |
130 ms |
216288 KB |
Output is correct |
5 |
Correct |
130 ms |
216312 KB |
Output is correct |
6 |
Correct |
117 ms |
216312 KB |
Output is correct |
7 |
Correct |
122 ms |
216312 KB |
Output is correct |
8 |
Correct |
255 ms |
216312 KB |
Output is correct |
9 |
Correct |
118 ms |
216312 KB |
Output is correct |
10 |
Correct |
119 ms |
216312 KB |
Output is correct |
11 |
Correct |
124 ms |
216312 KB |
Output is correct |
12 |
Correct |
119 ms |
216312 KB |
Output is correct |
13 |
Correct |
120 ms |
216312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1506 ms |
216312 KB |
Output is correct |
2 |
Correct |
137 ms |
216312 KB |
Output is correct |
3 |
Correct |
127 ms |
216312 KB |
Output is correct |
4 |
Correct |
130 ms |
216288 KB |
Output is correct |
5 |
Correct |
130 ms |
216312 KB |
Output is correct |
6 |
Correct |
117 ms |
216312 KB |
Output is correct |
7 |
Correct |
122 ms |
216312 KB |
Output is correct |
8 |
Correct |
255 ms |
216312 KB |
Output is correct |
9 |
Correct |
118 ms |
216312 KB |
Output is correct |
10 |
Correct |
119 ms |
216312 KB |
Output is correct |
11 |
Correct |
124 ms |
216312 KB |
Output is correct |
12 |
Correct |
119 ms |
216312 KB |
Output is correct |
13 |
Correct |
120 ms |
216312 KB |
Output is correct |
14 |
Correct |
136 ms |
216312 KB |
Output is correct |
15 |
Correct |
116 ms |
216440 KB |
Output is correct |
16 |
Correct |
122 ms |
216312 KB |
Output is correct |
17 |
Correct |
119 ms |
216312 KB |
Output is correct |
18 |
Correct |
123 ms |
216312 KB |
Output is correct |
19 |
Correct |
129 ms |
216332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1506 ms |
216312 KB |
Output is correct |
2 |
Correct |
137 ms |
216312 KB |
Output is correct |
3 |
Correct |
127 ms |
216312 KB |
Output is correct |
4 |
Correct |
130 ms |
216288 KB |
Output is correct |
5 |
Correct |
130 ms |
216312 KB |
Output is correct |
6 |
Correct |
117 ms |
216312 KB |
Output is correct |
7 |
Correct |
122 ms |
216312 KB |
Output is correct |
8 |
Correct |
255 ms |
216312 KB |
Output is correct |
9 |
Correct |
118 ms |
216312 KB |
Output is correct |
10 |
Correct |
119 ms |
216312 KB |
Output is correct |
11 |
Correct |
124 ms |
216312 KB |
Output is correct |
12 |
Correct |
119 ms |
216312 KB |
Output is correct |
13 |
Correct |
120 ms |
216312 KB |
Output is correct |
14 |
Correct |
136 ms |
216312 KB |
Output is correct |
15 |
Correct |
116 ms |
216440 KB |
Output is correct |
16 |
Correct |
122 ms |
216312 KB |
Output is correct |
17 |
Correct |
119 ms |
216312 KB |
Output is correct |
18 |
Correct |
123 ms |
216312 KB |
Output is correct |
19 |
Correct |
129 ms |
216332 KB |
Output is correct |
20 |
Correct |
119 ms |
216312 KB |
Output is correct |
21 |
Correct |
117 ms |
216316 KB |
Output is correct |
22 |
Correct |
123 ms |
216312 KB |
Output is correct |
23 |
Correct |
133 ms |
216312 KB |
Output is correct |
24 |
Correct |
144 ms |
216296 KB |
Output is correct |
25 |
Correct |
191 ms |
216444 KB |
Output is correct |