#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define all(aa) aa.begin(), aa.end()
int main(){
int n, L, R, C;
cin>>n>>L>>R>>C;
vector<int> val(n+1);
int ans=0;
for(int i=1; i<=n; i++){
cin>>val[i];
if(i>=L && i<=R) ans+=val[i];
}
vector<vector<vector<int>>> dp_l(L+2, vector<vector<int>>(n-R+2, vector<int>(C+1)));
for(int i=R; i>=L; i--){
vector<vector<vector<int>>> dp(L+2, vector<vector<int>>(n-R+2, vector<int>(C+1)));
for(int l=0; l<=L-1; l++){
for(int rr=n+1; rr>=R+1; rr--){
for(int c=0; c<=C; c++){
int r=rr-R-1;
dp[l][r][c]=dp_l[l][r][c];
if(l>0){
if(c>=i-l)
dp[l][r][c]=min(dp[l][r][c], dp_l[l-1][r][c-(i-l)]+val[l]-val[i]);
dp[l][r][c]=min(dp[l][r][c], dp[l-1][r][c]);
}
if(rr<=n){
if(c>=rr-i)
dp[l][r][c]=min(dp[l][r][c], dp_l[l][r+1][c-(rr-i)]+val[rr]-val[i]);
dp[l][r][c]=min(dp[l][r][c], dp[l][r+1][c]);
}
}
}
}
dp_l=dp;
}
cout<<ans+dp_l[L-1][0][C];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
3 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
3 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
36 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
3 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
36 ms |
4700 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
1180 KB |
Output is correct |
18 |
Correct |
8 ms |
1140 KB |
Output is correct |
19 |
Correct |
32 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
3 ms |
1628 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
36 ms |
4700 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
4 ms |
1180 KB |
Output is correct |
18 |
Correct |
8 ms |
1140 KB |
Output is correct |
19 |
Correct |
32 ms |
4700 KB |
Output is correct |
20 |
Correct |
32 ms |
3572 KB |
Output is correct |
21 |
Correct |
53 ms |
13648 KB |
Output is correct |
22 |
Correct |
3 ms |
792 KB |
Output is correct |
23 |
Correct |
25 ms |
14684 KB |
Output is correct |
24 |
Correct |
12 ms |
604 KB |
Output is correct |
25 |
Correct |
127 ms |
8684 KB |
Output is correct |