Submission #736097

#TimeUsernameProblemLanguageResultExecution timeMemory
736097Huseyn123Holding (COCI20_holding)C++17
55 / 110
160 ms22412 KiB
#include <bits/stdc++.h>
#define MAX 200001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
    for(int i=0;i<b;i++){\
        cin >> a[i];\
    }\
}
#define inputvec(a,b){\
    for(int i=0;i<b;i++){\
        ll num;\
        cin >> num;\
        a.pb(num);\
    }\
}
#define outputar(a,b){\
    for(int i=0;i<b;i++){\
        cout << a[i] << " ";\
    }\
    cout << "\n";\
}
#define outputvec(a){\
    for(auto x:a){\
        cout << x << " ";\
    }\
    cout << "\n";\
}
#define reset(a,n,v){\
    for(int i=0;i<n;i++){\
        a[i]=v;\
    }\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
ll n,q,t=1,m,n2,m2,k,cnt=0,x,y,z,x2,y2,z2,res1=0,a[MAX],b[MAX],d[MAX];
ll c[1501][1501];
ll fact[MAX];
ll inv_fact[MAX];
string str[MAX];
string s1,s2;
const int mod = 998244353;
ll dx[4]={1,0,0,-1};
ll dy[4]={0,1,-1,0};
struct custom_hash {
   static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
const ll M=10001;
const ll N=101;
ll dp[M][N];
ll dp2[M][N];
void solve(){
    cin >> n >> x >> y >> k;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    x--;
    y--;
    for(int i=0;i<M;i++){
        for(int j=0;j<N;j++){
            dp[i][j]=INF;
            dp2[i][j]=-INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<x;i++){
        ll h=x-i;
        for(int j=n;j>=1;j--){
            for(int z=k;z>=h;z--){
                if(dp[z-h][j-1]==INF){
                    continue;
                }
                dp[z][j]=min(dp[z][j],dp[z-h][j-1]+a[i]);
            }
        }
    }
    dp2[0][0]=0;
    for(int i=x;i<n;i++){
        ll h=i-x;
        for(int j=n;j>=1;j--){
            for(int z=k;z>=h;z--){
                if(dp2[z-h][j-1]==-INF){
                    continue;
                }
                dp2[z][j]=max(dp2[z][j],dp2[z-h][j-1]+a[i]);
            }
        }
    }
    ll res,sum;
    res=sum=0;
    for(int i=x;i<n;i++){
        sum+=a[i];
    }
    res=sum;
    for(int i=0;i<=n;i++){
        ll h=-INF;
        for(int j=k;j>=0;j--){
            if(dp2[k-j][i]>h){
                h=dp2[k-j][i];
            }
            if(h!=-INF && dp[j][i]!=INF){
                res=min(res,sum-(h-dp[j][i]));
            }
        }
    }
    cout << res << "\n";
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //USACO("poetry");
    //freopen("input.txt","r",stdin);
    //cin >> t;
    ll cnt1=1;
    while(t--){
        solve();
        cnt1++;
    }
}
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
ll b[51][51];
b[0][0] = 1;
    for (int n = 1; n <= 50; ++n){
        b[n][0] = b[n][n] = 1;
        for (int k = 1; k < n; ++k)
            b[n][k] = b[n - 1][k - 1] + b[n - 1][k];
    }
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...