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;
long long b[1000005], n,a[1000005],mn,mx,raod,x,w,ww;
pair <long long ,long long > dp[1000005];
int main()
{
cin>>n;
a[0]=1e9;
for (int i=1; i<=n; i++) {
cin>>a[i];
mx=max(mx,a[i]);
if (a[i]>a[i-1]) ww=1;
}
if (n>1500) {
cout<<mx*n<<endl;
return 0;
}
dp[0]={0,0};
dp[1]={a[1]+(n-1)*a[1],a[1]};
for (int i=2; i<=n; i++) {
dp[i].first=1e18;
x=0;
for (int j=i; j>=1; j--) {
x=max(x,a[j]);
dp[i].first=min(dp[i].first, dp[j-1].first+(n-j+1)*x);
}
}
cout<<dp[n].first;
}
# | 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... |