#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> A;
vector<vector<int>> dp;
int main() {
int N, L, R, K;
cin >> N >> L >> R >> K;
A = vector<int>(N + 1);
dp = vector<vector<int>>(102, vector<int>(10205, 1e9));
for (int i = 1; i <= N; i++)
cin >> A[i];
dp[0][0] = 0;
int ans = 1e9;
for (int i = 1; i <= N; i++) {
vector<vector<int>> ndp(102, vector<int>(10205, 1e9));
for (int cnt = 0; cnt <= i; cnt++) {
int cost = abs(L + cnt - i);
for (int last = 0; last <= K; last++) {
ndp[cnt][last] = min(ndp[cnt][last], dp[cnt][last]);
ndp[cnt + 1][cost + last] = min(ndp[cnt + 1][cost + last], dp[cnt][last] + A[i]);
if (cnt+1 == R - L + 1 && cost + last <= K)
ans = min(ans, ndp[cnt + 1][cost + last]);
}
}
dp = ndp;
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8632 KB |
Output is correct |
2 |
Correct |
22 ms |
8676 KB |
Output is correct |
3 |
Correct |
20 ms |
8744 KB |
Output is correct |
4 |
Correct |
21 ms |
8676 KB |
Output is correct |
5 |
Correct |
21 ms |
8688 KB |
Output is correct |
6 |
Correct |
20 ms |
8676 KB |
Output is correct |
7 |
Correct |
20 ms |
8636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8632 KB |
Output is correct |
2 |
Correct |
22 ms |
8676 KB |
Output is correct |
3 |
Correct |
20 ms |
8744 KB |
Output is correct |
4 |
Correct |
21 ms |
8676 KB |
Output is correct |
5 |
Correct |
21 ms |
8688 KB |
Output is correct |
6 |
Correct |
20 ms |
8676 KB |
Output is correct |
7 |
Correct |
20 ms |
8636 KB |
Output is correct |
8 |
Correct |
71 ms |
8900 KB |
Output is correct |
9 |
Correct |
74 ms |
8836 KB |
Output is correct |
10 |
Correct |
74 ms |
8904 KB |
Output is correct |
11 |
Correct |
74 ms |
8792 KB |
Output is correct |
12 |
Correct |
74 ms |
8728 KB |
Output is correct |
13 |
Correct |
90 ms |
8772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8632 KB |
Output is correct |
2 |
Correct |
22 ms |
8676 KB |
Output is correct |
3 |
Correct |
20 ms |
8744 KB |
Output is correct |
4 |
Correct |
21 ms |
8676 KB |
Output is correct |
5 |
Correct |
21 ms |
8688 KB |
Output is correct |
6 |
Correct |
20 ms |
8676 KB |
Output is correct |
7 |
Correct |
20 ms |
8636 KB |
Output is correct |
8 |
Correct |
71 ms |
8900 KB |
Output is correct |
9 |
Correct |
74 ms |
8836 KB |
Output is correct |
10 |
Correct |
74 ms |
8904 KB |
Output is correct |
11 |
Correct |
74 ms |
8792 KB |
Output is correct |
12 |
Correct |
74 ms |
8728 KB |
Output is correct |
13 |
Correct |
90 ms |
8772 KB |
Output is correct |
14 |
Correct |
76 ms |
8736 KB |
Output is correct |
15 |
Correct |
74 ms |
8728 KB |
Output is correct |
16 |
Correct |
70 ms |
8768 KB |
Output is correct |
17 |
Correct |
71 ms |
8772 KB |
Output is correct |
18 |
Correct |
73 ms |
8948 KB |
Output is correct |
19 |
Correct |
92 ms |
8720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8632 KB |
Output is correct |
2 |
Correct |
22 ms |
8676 KB |
Output is correct |
3 |
Correct |
20 ms |
8744 KB |
Output is correct |
4 |
Correct |
21 ms |
8676 KB |
Output is correct |
5 |
Correct |
21 ms |
8688 KB |
Output is correct |
6 |
Correct |
20 ms |
8676 KB |
Output is correct |
7 |
Correct |
20 ms |
8636 KB |
Output is correct |
8 |
Correct |
71 ms |
8900 KB |
Output is correct |
9 |
Correct |
74 ms |
8836 KB |
Output is correct |
10 |
Correct |
74 ms |
8904 KB |
Output is correct |
11 |
Correct |
74 ms |
8792 KB |
Output is correct |
12 |
Correct |
74 ms |
8728 KB |
Output is correct |
13 |
Correct |
90 ms |
8772 KB |
Output is correct |
14 |
Correct |
76 ms |
8736 KB |
Output is correct |
15 |
Correct |
74 ms |
8728 KB |
Output is correct |
16 |
Correct |
70 ms |
8768 KB |
Output is correct |
17 |
Correct |
71 ms |
8772 KB |
Output is correct |
18 |
Correct |
73 ms |
8948 KB |
Output is correct |
19 |
Correct |
92 ms |
8720 KB |
Output is correct |
20 |
Correct |
142 ms |
8744 KB |
Output is correct |
21 |
Correct |
145 ms |
8752 KB |
Output is correct |
22 |
Correct |
145 ms |
8792 KB |
Output is correct |
23 |
Correct |
167 ms |
8788 KB |
Output is correct |
24 |
Correct |
144 ms |
8740 KB |
Output is correct |
25 |
Correct |
214 ms |
8676 KB |
Output is correct |