Submission #1183362

#TimeUsernameProblemLanguageResultExecution timeMemory
1183362al95ireyizHolding (COCI20_holding)C++20
22 / 110
1 ms328 KiB
//*** Bismillah ***//
// It's the evening of another day. And the end of mine...
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#if !defined(ONLINE_JUDGE) and !defined(EVAL)
#include "template/debug.h"
#else
#define d(x...)
#endif
#define ll long long
#define love 0
const ll INF = 1e9;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;
const ll maxn = 100 + 5;
ll n,m,k=0;
ll l,r,d,a[maxn];
void _(){
    cin>>n>>l>>r>>d;
    for(ll i=1;i<=n;i++) cin>>a[i];
    // mask :
    // 1 -> select, 2 -> dont select

    ll cv = INF;
    for(ll i=1;i<(1<<n);i++){
        if(__builtin_popcountll(i) != r - l + 1) continue;
        ll nw = l, tmp=0, cm = 0;
        for(ll j=0;j<n;j++){
            if(i&(1<<j)){
                tmp += abs(nw - (j+1));
                cm += a[j+1];
                nw ++;
            }
        }
        if(tmp <= d){
            cv = min(cv, cm);
        }
    }
    cout<<cv<<'\n';
}
signed main(){
    auto testcaseruntime=clock();
    cin.tie(0)->sync_with_stdio(0);
    ll t=1;
    // cin>>t;
    while(t--){
        _();
    }
    cerr<<"\n\033[1;31mTime: \033[1;30m"
        <<(double)(clock()-testcaseruntime)/1000000
        <<"\033[1;32m seconds";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...