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
const int nx=1e6+5;
ll n, t[nx], dp[nx][2];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>t[i];
for (int i=1; i<=n; i++)
{
ll mx=t[i]; dp[i][0]=dp[i][1]=1e18;
for (int j=i-1; j>=0; j--)
{
if (dp[j][0]+(dp[j][1]+mx)*(i-j)<dp[i][0])
{
dp[i][0]=dp[j][0]+(dp[j][1]+mx)*(i-j);
dp[i][1]=dp[j][1]+mx;
}
mx=max(mx, t[j]);
}
//cout<<i<<' '<<dp[i][0]<<' '<<dp[i][1]<<'\n';
}
cout<<dp[n][0];
}
# | 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... |