Submission #764512

#TimeUsernameProblemLanguageResultExecution timeMemory
764512TrunktySkyline (IZhO11_skyline)C++14
100 / 100
62 ms980 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,tot;
int arr[305];
int dp[205][205],dp2[205][205];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> arr[i];
        tot += 3LL*arr[i];
    }
    for(int j=0;j<=200;j++){
        for(int k=0;k<=200;k++){
            dp[j][k] = -2e9;
            dp2[j][k] = -2e9;
        }
    }
    dp[0][0] = 0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=200;j++){
            for(int k=0;k<=200;k++){
                int x = min(arr[i],min(j,k));
                dp2[k-x][arr[i]-x] = max(dp2[k-x][arr[i]-x],dp[j][k]+x*2LL);
            }
        }
        for(int j=200;j>=1;j--){
            for(int k=200;k>=1;k--){
                dp2[j-1][k-1] = max(dp2[j-1][k-1],dp2[j][k]+1LL);
            }
        }
        for(int j=0;j<=200;j++){
            for(int k=0;k<=200;k++){
                dp[j][k] = dp2[j][k];
                dp2[j][k] = -2e9;
            }
        }
    }
    int maxi=0;
    for(int j=0;j<=200;j++){
        for(int k=0;k<=200;k++){
            maxi = max(maxi,dp[j][k]);
        }
    }
    cout << tot-maxi << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...