#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
void solve() {
    int n;
    cin>>n;
    ll a[n+1];
    for(int i=1;i<=n;i++)cin>>a[i];
    ll dp[n+1];
    dp[0]=0;
    for(int i=1;i<=n;i++){
        dp[i]=1e18;
        ll m=0;
        for(int j=i;j;j--){
            m=max(m,a[j]);
            dp[i]=min(dp[i],dp[j-1]+m*(n-j+1));
        }
    }
    cout<<dp[n]<<'\n';
}
int main() {
    #ifdef FPO
        freopen("in","r",stdin);
        freopen("out","w",stdout);
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
}
| # | 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... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |