#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 998244353;
const ll LOGN = 20;
const ll MAXN = 1e6 + 5;
vector<int> A;
vector<vector<int>> dp;
int main() {
fast
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>> new_dp(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++) {
new_dp[cnt][last] = min(new_dp[cnt][last], dp[cnt][last]);
new_dp[cnt + 1][cost + last] = min(new_dp[cnt + 1][cost + last], dp[cnt][last] + A[i]);
if (cnt+1 == R - L + 1 && cost + last <= K)
ans = min(ans, new_dp[cnt+1][cost+last]);
}
}
dp = new_dp;
}
cout << ans << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8636 KB |
Output is correct |
2 |
Correct |
18 ms |
8684 KB |
Output is correct |
3 |
Correct |
18 ms |
8672 KB |
Output is correct |
4 |
Correct |
18 ms |
8936 KB |
Output is correct |
5 |
Correct |
18 ms |
8724 KB |
Output is correct |
6 |
Correct |
18 ms |
8732 KB |
Output is correct |
7 |
Correct |
18 ms |
8936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8636 KB |
Output is correct |
2 |
Correct |
18 ms |
8684 KB |
Output is correct |
3 |
Correct |
18 ms |
8672 KB |
Output is correct |
4 |
Correct |
18 ms |
8936 KB |
Output is correct |
5 |
Correct |
18 ms |
8724 KB |
Output is correct |
6 |
Correct |
18 ms |
8732 KB |
Output is correct |
7 |
Correct |
18 ms |
8936 KB |
Output is correct |
8 |
Correct |
72 ms |
8824 KB |
Output is correct |
9 |
Correct |
65 ms |
8800 KB |
Output is correct |
10 |
Correct |
71 ms |
8852 KB |
Output is correct |
11 |
Correct |
63 ms |
8816 KB |
Output is correct |
12 |
Correct |
63 ms |
8928 KB |
Output is correct |
13 |
Correct |
86 ms |
8752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8636 KB |
Output is correct |
2 |
Correct |
18 ms |
8684 KB |
Output is correct |
3 |
Correct |
18 ms |
8672 KB |
Output is correct |
4 |
Correct |
18 ms |
8936 KB |
Output is correct |
5 |
Correct |
18 ms |
8724 KB |
Output is correct |
6 |
Correct |
18 ms |
8732 KB |
Output is correct |
7 |
Correct |
18 ms |
8936 KB |
Output is correct |
8 |
Correct |
72 ms |
8824 KB |
Output is correct |
9 |
Correct |
65 ms |
8800 KB |
Output is correct |
10 |
Correct |
71 ms |
8852 KB |
Output is correct |
11 |
Correct |
63 ms |
8816 KB |
Output is correct |
12 |
Correct |
63 ms |
8928 KB |
Output is correct |
13 |
Correct |
86 ms |
8752 KB |
Output is correct |
14 |
Correct |
61 ms |
8812 KB |
Output is correct |
15 |
Correct |
68 ms |
8892 KB |
Output is correct |
16 |
Correct |
64 ms |
8852 KB |
Output is correct |
17 |
Correct |
64 ms |
8780 KB |
Output is correct |
18 |
Correct |
64 ms |
8840 KB |
Output is correct |
19 |
Correct |
91 ms |
8728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8636 KB |
Output is correct |
2 |
Correct |
18 ms |
8684 KB |
Output is correct |
3 |
Correct |
18 ms |
8672 KB |
Output is correct |
4 |
Correct |
18 ms |
8936 KB |
Output is correct |
5 |
Correct |
18 ms |
8724 KB |
Output is correct |
6 |
Correct |
18 ms |
8732 KB |
Output is correct |
7 |
Correct |
18 ms |
8936 KB |
Output is correct |
8 |
Correct |
72 ms |
8824 KB |
Output is correct |
9 |
Correct |
65 ms |
8800 KB |
Output is correct |
10 |
Correct |
71 ms |
8852 KB |
Output is correct |
11 |
Correct |
63 ms |
8816 KB |
Output is correct |
12 |
Correct |
63 ms |
8928 KB |
Output is correct |
13 |
Correct |
86 ms |
8752 KB |
Output is correct |
14 |
Correct |
61 ms |
8812 KB |
Output is correct |
15 |
Correct |
68 ms |
8892 KB |
Output is correct |
16 |
Correct |
64 ms |
8852 KB |
Output is correct |
17 |
Correct |
64 ms |
8780 KB |
Output is correct |
18 |
Correct |
64 ms |
8840 KB |
Output is correct |
19 |
Correct |
91 ms |
8728 KB |
Output is correct |
20 |
Correct |
128 ms |
8924 KB |
Output is correct |
21 |
Correct |
132 ms |
8764 KB |
Output is correct |
22 |
Correct |
133 ms |
8936 KB |
Output is correct |
23 |
Correct |
168 ms |
8812 KB |
Output is correct |
24 |
Correct |
134 ms |
8804 KB |
Output is correct |
25 |
Correct |
209 ms |
8844 KB |
Output is correct |