#include <bits/stdc++.h>
using namespace std;
int dp[105][10005];
int dplast[105][10005];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, left, right, k; cin >> n >> left >> right >> k;
vector<int> a(n+1);
for (int i = 1; i <= n; i++) cin >> a[i];
int sum = 0;
for (int i = left; i <= right; i++) sum+=a[i];
for(int l=0; l<=n; l++){
for(int j=0; j<=k; j++){
dp[l][j]=dplast[l][j]=sum;
}
}
int ans=sum;
for(int i=1; i<=n; i++){
if(i>=left&&i<=right) continue;
for(int l=left; l<=right; l++){
for(int j=0; j<=k; j++){
dp[l][j] = min(dp[l-1][j], dplast[l-1][j]);
dp[l][j] = min(dp[l][j], dplast[l][j]);
if(j>=abs(l-i))
dp[l][j] = min(dp[l][j], dplast[l-1][j-abs(l-i)]-a[l]+a[i]);
ans=min(ans, dp[l][j]);
}
}
swap(dplast, dp);
for(int l=0; l<=n; l++){
for(int j=0; j<=k; j++){
dp[l][j]=sum;
}
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8540 KB |
Output is correct |
2 |
Correct |
6 ms |
8536 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
3 ms |
8536 KB |
Output is correct |
5 |
Correct |
3 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
7 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8540 KB |
Output is correct |
2 |
Correct |
6 ms |
8536 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
3 ms |
8536 KB |
Output is correct |
5 |
Correct |
3 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
7 ms |
8540 KB |
Output is correct |
8 |
Correct |
27 ms |
8536 KB |
Output is correct |
9 |
Correct |
26 ms |
8536 KB |
Output is correct |
10 |
Correct |
19 ms |
8540 KB |
Output is correct |
11 |
Correct |
19 ms |
8536 KB |
Output is correct |
12 |
Correct |
8 ms |
8536 KB |
Output is correct |
13 |
Correct |
46 ms |
8536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8540 KB |
Output is correct |
2 |
Correct |
6 ms |
8536 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
3 ms |
8536 KB |
Output is correct |
5 |
Correct |
3 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
7 ms |
8540 KB |
Output is correct |
8 |
Correct |
27 ms |
8536 KB |
Output is correct |
9 |
Correct |
26 ms |
8536 KB |
Output is correct |
10 |
Correct |
19 ms |
8540 KB |
Output is correct |
11 |
Correct |
19 ms |
8536 KB |
Output is correct |
12 |
Correct |
8 ms |
8536 KB |
Output is correct |
13 |
Correct |
46 ms |
8536 KB |
Output is correct |
14 |
Correct |
35 ms |
8536 KB |
Output is correct |
15 |
Correct |
33 ms |
8536 KB |
Output is correct |
16 |
Correct |
30 ms |
8536 KB |
Output is correct |
17 |
Correct |
30 ms |
8536 KB |
Output is correct |
18 |
Correct |
26 ms |
8536 KB |
Output is correct |
19 |
Correct |
41 ms |
8792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8540 KB |
Output is correct |
2 |
Correct |
6 ms |
8536 KB |
Output is correct |
3 |
Correct |
1 ms |
6488 KB |
Output is correct |
4 |
Correct |
3 ms |
8536 KB |
Output is correct |
5 |
Correct |
3 ms |
8536 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
7 ms |
8540 KB |
Output is correct |
8 |
Correct |
27 ms |
8536 KB |
Output is correct |
9 |
Correct |
26 ms |
8536 KB |
Output is correct |
10 |
Correct |
19 ms |
8540 KB |
Output is correct |
11 |
Correct |
19 ms |
8536 KB |
Output is correct |
12 |
Correct |
8 ms |
8536 KB |
Output is correct |
13 |
Correct |
46 ms |
8536 KB |
Output is correct |
14 |
Correct |
35 ms |
8536 KB |
Output is correct |
15 |
Correct |
33 ms |
8536 KB |
Output is correct |
16 |
Correct |
30 ms |
8536 KB |
Output is correct |
17 |
Correct |
30 ms |
8536 KB |
Output is correct |
18 |
Correct |
26 ms |
8536 KB |
Output is correct |
19 |
Correct |
41 ms |
8792 KB |
Output is correct |
20 |
Correct |
64 ms |
8652 KB |
Output is correct |
21 |
Correct |
70 ms |
8536 KB |
Output is correct |
22 |
Correct |
62 ms |
8792 KB |
Output is correct |
23 |
Correct |
93 ms |
8536 KB |
Output is correct |
24 |
Correct |
27 ms |
8540 KB |
Output is correct |
25 |
Correct |
132 ms |
8540 KB |
Output is correct |