| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 308324 | ErdosSzekeres | Holding (COCI20_holding) | C++14 | 121 ms | 26488 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 103;
const int MAXK = (MAXN*MAXN)/4 + 3;
int dpL[MAXN][MAXN][MAXK], dpR[MAXN][MAXN][MAXK], n,l,r,k, a[MAXN];
int main(){
    scanf("%d %d %d %d", &n, &l, &r, &k);
    k = min(k, MAXK - 1);
    for(int i=1; i<=n; i++)scanf("%d", &a[i]);
    int orig = 0; for(int i=l; i<=r; i++)orig+=a[i];
    //compute dpL (base case dpL[][][0])
    for(int j=1; j<=k; j++){
        for(int i=1; i<=l-1; i++){
            for(int g=l; g<=r; g++){
                if(j >= g-i)dpL[i][g][j] = max(dpL[i][g][j], dpL[i-1][g-1][j-(g-i)] + a[g] - a[i]);//swap them
                dpL[i][g][j] = max(dpL[i][g][j], dpL[i-1][g][j]);
                dpL[i][g][j] = max(dpL[i][g][j], dpL[i][g-1][j]);
            }
        }
    }
    //compute dpR
    for(int j=1; j<=k; j++){
        for(int i=n; i>=r+1; i--){
            for(int g=r; g>=l; g--){
                if(j >= i-g)dpR[i][g][j] = max(dpR[i][g][j], dpR[i+1][g+1][j-(i-g)] + a[g] - a[i]);//swap them
                dpR[i][g][j] = max(dpR[i][g][j], dpR[i+1][g][j]);
                dpR[i][g][j] = max(dpR[i][g][j], dpR[i][g+1][j]);
            }
        }
    }
    int ans = 0;
    for(int i=l-1; i<=r+1; i++){//position of line
        for(int j=0; j<=k; j++){//money
            //cout<<i<<" "<<j<<" "<<dpL[l-1][i][j] + dpR[r+1][i+1][k-j]<<endl;
            ans = max(ans, dpL[l-1][i][j] + dpR[r+1][i+1][k-j]);
        }
    }
    cout << orig - ans << endl;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
