// NgJaBach: Forever Meadow <3
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long int ll;
typedef unsigned long long ull;
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define bend(a) a.begin(),a.end()
#define rev(x) reverse(bend(x))
#define mset(a) memset(a, 0, sizeof(a))
#define fi first
#define se second
#define gcd __gcd
#define getl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
#define endl '\n'
const int N=105,M=1000000007;
const ll INF=1e18+7;
int n,L,R,k,a[N];
namespace sub2{
int dp[N][N][N*N/4];
int solve(){
k=min(k,n*n/4);
for(int i=0;i<=n;++i){
for(int j=0;j<=n;++j){
for(int d=0;d<=k;++d){
dp[i][j][d]=0;
}
}
}
for(int i=1;i<L;++i){
for(int j=L;j<=n;++j){
for(int d=0;d<=k;++d){
dp[i][j][d]=max(dp[i-1][j][d],dp[i][j-1][d]);
int cost=j-i;
if(d>=cost) dp[i][j][d]=max(dp[i][j][d],dp[i-1][j-1][d-cost]+a[j]-a[i]);
}
}
}
int ans=0,sum=0;
for(int i=1;i<L;++i){
for(int d=0;d<=k;++d){
ans=max(ans,dp[i][n][d]);
}
}
for(int i=L;i<=R;++i) sum+=a[i];
// cout<<sum<<" "<<ans<<endl;
return sum-ans;
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
// freopen("DEBT.inp","r",stdin);
// freopen("DEBT.out","w",stdout);
cin>>n>>L>>R>>k;
for(int i=1;i<=n;++i) cin>>a[i];
if(n<=50 and R==n) cout<<sub2::solve();
return 0;
}
/*
==================================+
INPUT: |
------------------------------ |
------------------------------ |
==================================+
OUTPUT: |
------------------------------ |
------------------------------ |
==================================+
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
16732 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
16732 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
16732 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
16732 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
7 ms |
58200 KB |
Output is correct |
9 |
Correct |
6 ms |
57948 KB |
Output is correct |
10 |
Correct |
6 ms |
57944 KB |
Output is correct |
11 |
Correct |
7 ms |
57944 KB |
Output is correct |
12 |
Correct |
6 ms |
57948 KB |
Output is correct |
13 |
Correct |
8 ms |
57944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
16732 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
16732 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
7 ms |
58200 KB |
Output is correct |
9 |
Correct |
6 ms |
57948 KB |
Output is correct |
10 |
Correct |
6 ms |
57944 KB |
Output is correct |
11 |
Correct |
7 ms |
57944 KB |
Output is correct |
12 |
Correct |
6 ms |
57948 KB |
Output is correct |
13 |
Correct |
8 ms |
57944 KB |
Output is correct |
14 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
16732 KB |
Output is correct |
3 |
Correct |
2 ms |
16732 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
2 ms |
16732 KB |
Output is correct |
6 |
Correct |
2 ms |
16732 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
7 ms |
58200 KB |
Output is correct |
9 |
Correct |
6 ms |
57948 KB |
Output is correct |
10 |
Correct |
6 ms |
57944 KB |
Output is correct |
11 |
Correct |
7 ms |
57944 KB |
Output is correct |
12 |
Correct |
6 ms |
57948 KB |
Output is correct |
13 |
Correct |
8 ms |
57944 KB |
Output is correct |
14 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |