#pragma GCC optimize("O3", "inline")
#define skillissue <bits/stdc++.h>
#define ultra_mal std
#include skillissue
using namespace ultra_mal;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ins insert
#define pb push_back
#define int long long int
#define pii pair<int, int>
#define endl '\n'
#define drop(x) cout<<(x)<<endl; return;
#define all(x) x.begin(),x.end()
#define hash FhashF
const int mod = 1e9 +7, sze = 1e4 +10, inf = LLONG_MAX, P = 1453;
// const int L = 30;
int dp[111][111][sze];
int dp2[111][111][sze];
void optimus(){
int n,l,r,k;
cin>>n>>l>>r>>k;
vector<int> arr(n+1);
for(int i=1;i<=n;i++){
cin>>arr[i];
}
int sum=0;
for(int i = l;i<=r;i++){
sum+=arr[i];
}
for(int i =1;i<l;i++){
for(int j= l;j<=r;j++){
for(int p=0;p<=k;p++){
dp[i][j][p]= max({
dp[i-1][j][p],
dp[i][j-1][p],
(int)0
});
if((j-i)<=p){
dp[i][j][p]=max(dp[i][j][p],dp[i-1][j-1][p - (j-i)] + arr[j]-arr[i]);
}
// cout<<i<<" "<<j<<" "<<p<<" "<<dp[i][j][p]<<" "<<
// dp[i-1][j-1][p - (j-i)]+ arr[i]- arr[j]<<endl;
}
}
}
/*
r+1- >n
l->r
*/
for(int i =r;i>=l;i++){
for(int j= r+1;j<=n;j++){
for(int p=0;p<=k;p++){
dp2[i][j][p]= max({
dp2[i+1][j][p],
dp2[i][j-1][p],
(int)0
});
if((j-i)<=p){
dp2[i][j][p]=max(dp2[i][j][p],dp2[i+1][j-1][p - (j-i)] + arr[j]-arr[i]);
}
// cout<<i<<" "<<j<<" "<<p<<" "<<dp[i][j][p]<<" "<<
// dp[i-1][j-1][p - (j-i)]+ arr[i]- arr[j]<<endl;
}
}
}
int mx =0 ;
for(int i = l-1;i<=r;i++){
for(int j=0;j<=k;j++){
mx=max(mx, dp[l-1][i][j] + dp2[n][i+1][k - j]);
}
}
drop(sum - mx);
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int tt = 1;
// cin>>tt;
while(tt--){
optimus();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 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 |
2 ms |
3164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 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 |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
2136 KB |
Output is correct |
13 |
Correct |
31 ms |
49488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 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 |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
2136 KB |
Output is correct |
13 |
Correct |
31 ms |
49488 KB |
Output is correct |
14 |
Runtime error |
21 ms |
18520 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 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 |
2 ms |
3164 KB |
Output is correct |
8 |
Correct |
2 ms |
2652 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
2 ms |
3420 KB |
Output is correct |
11 |
Correct |
2 ms |
3676 KB |
Output is correct |
12 |
Correct |
1 ms |
2136 KB |
Output is correct |
13 |
Correct |
31 ms |
49488 KB |
Output is correct |
14 |
Runtime error |
21 ms |
18520 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |