#include<bits/stdc++.h>
//#define int long long
#define d0 1
#define d1 11
#define d2 110
#define d3 1010
#define d4 10010
#define d5 100010
#define d6 1000010
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define debug(x) cerr<<x<<" ";
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define sz(s) s.size()
#define pii pair<int,int>
#define pb push_back
#define checktime cout << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define reb(i,m,n) for(int i=m;i>=n;i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
void phongbeo();
void de();
template<typename A, typename B>istream& operator>>(istream& in, pair<A, B> &v) {
in >> v.first >> v.second;
return in;
}
template<typename A, typename B> ostream& operator<<(ostream& out, const pair<A, B> &v) {
out << v.first << " " << v.second << " ";
return out;
}
template < class T > bool minimize(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template < class T > bool maximize(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count ());
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy2[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int mod2=1e9+7;
const int mod=1073741824;
const int mod1=998244353;
struct ib {
int a;
int b;
};
struct icd {
int a,b;
};
struct ic {
int a,b,c;
};
struct id {
int a,b,c,d;
};
int minn=1e9,maxx=-1e9;
int n,m,s2,s4,s3,sf,k,l,r,dem=0,l1,r1,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0;
int s,i;
int el=29;
main() {
#ifndef ONLINE_JUDGE
fin(task),fou(task);
#endif
NHP
//modwwe
phongbeo(),down
#ifndef ONLINE_JUDGE
//checktime
#endif
}
int a[101],b[101],dp[102][10002][2],dp2[102][10002][2];
void phongbeo()
{
cin>>n>>l>>r>>k;
for(int i=1;i<=n;i++)
cin>>a[i],b[i]=b[i-1]+a[i];
for(int i=1;i<=n;i++)
for(int j=0;j<=k;j++){
if(i>=l&&i<=r){dp[i][j][0]=1e8;dp[i][j][1]=b[i]-b[l-1];}
if(i<=r&&i>=l1)dp2[i][j][1]=b[r]-b[i-1],dp2[i][j][0]=1e8;
}
for(int j=1;j<=l-1;j++){
for(int i=l;i<=r;i++){
for(int z=0;z<=k-i+j;z++)
{
dp[i][z+i-j][0]=min({dp[i][z+i-j][0],dp[i-1][z][1]+a[j],dp[i-1][z+i-j][0]+a[i]});
//dp[i][z][0]=min(dp[i-1][z][1]+a[i],dp[i][z][0]);
//cout<<dp[i][z+i-j][0]<<" "<<i<<" "<<j<<" "<<z<<" "<<z+i-j<<" "<<dp[i-1][z+i-j][0]<<" "<<dp[i-1][z][1]+a[j],down
}
for(int z=0;z<=k;z++){
dp[i][z][0]=min({dp[i-1][z][0]+a[i],dp[i-1][z][1]+a[i],dp[i][z][0]});
}
}
for(int i=l;i<=r;i++)
for(int z=0;z<=k;z++)
dp[i][z][1]=min(dp[i][z][1],dp[i][z][0]),
dp[i][z][0]=1e8;
// for(int z=k+j-i+1;z<=k;z++)
// dp[i][z]=min(dp[i][z],dp[i-1][z]+a[i]);
}
for(int j=n;j>=r+1;j--){
for(int i=r;i>=l;--i){
for(int z=0;z<=k-i+j;z++){
dp2[i][z+j-i][0]=min({dp2[i][z+j-i][0],dp2[i+1][z][1]+a[j],dp2[i+1][z+j-i][0]+a[i]});
//dp2[i][z]=min(dp2[i][z],dp2[i+1][z]+a[i]);
}
for(int z=0;z<=k;z++){
dp2[i][z][0]=min({dp2[i+1][z][0]+a[i],dp2[i+1][z][1]+a[i],dp2[i][z][0]});
}
}
for(int i=l;i<=r;i++)
for(int z=0;z<=k;z++)
dp2[i][z][1]=min(dp2[i][z][1],dp2[i][z][0]),
dp2[i][z][0]=1e8;
}
for(int i=l;i<=r;i++)
for(int z=1;z<=k;z++)
dp[i][z][1]=min(dp[i][z][1],dp[i][z-1][1]),dp2[i][z][1]=min(dp2[i][z-1][1],dp2[i][z][1]);
dem=b[r]-b[l-1];
///cout<<"3131e1e1\n";
for(int i=l-1;i<=r;i++)
for(int j=0;j<=k;j++){
dem=min(dem,dp[i][j][1]+dp2[i+1][k-j][1]);
//cout<<dp[i][j][1]<<" "<<dp2[i+1][k-j][1]<<" "<<i<<" "<<j,down
}
cout<<dem;
}
Compilation message
holding.cpp:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
68 | main() {
| ^~~~
holding.cpp: In function 'int main()':
holding.cpp:17:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
holding.cpp:70:1: note: in expansion of macro 'fin'
70 | fin(task),fou(task);
| ^~~
holding.cpp:18:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
holding.cpp:70:11: note: in expansion of macro 'fou'
70 | fin(task),fou(task);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |