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;
#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() {
ll n;
cin>>n;
ll a[n+1];
for(int i=1;i<=n;i++)cin>>a[i];
bool b=1;
for(int i=1;i<n;i++)b&=a[i]>=a[i+1];
if(b){
cout<<n*a[1];
return;
}
ll dp[n+1];
dp[0]=0;
for(int i=1;i<=n;i++){
dp[i]=1e18;
ll m=0;
for(ll j=i;j;j--){
m=max(m,a[j]);
dp[i]=min(dp[i],dp[j-1]+m*(n-j+1));
}
}
cout<<dp[n];
}
int main() {
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... |