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>
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second
#define __builtin_popcount __builtin_popcountll
#define sz(v) ((int) (v).size())
#define uni(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define pii(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
///
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const ll oo = 1e18 + 7;
const int N = 1e6 + 5;
int n, a[N], nxt[N];
ll dp[N];
void Input()
{
cin >> n;
for (int i = 1; i <= n; i ++) cin >> a[i];
nxt[1] = 1;
for (int i = 2; i <= n; i ++)
if (a[nxt[i - 1]] < a[i]) nxt[i] = i;
else nxt[i] = nxt[i - 1];
}
void solve()
{
for (int i = 1; i <= n; i ++)
{
dp[i] = 1LL * n * a[nxt[i]];
for (int j = 1; j < i; j ++)
dp[i] = min(dp[i], dp[j] + 1LL * (n - j) * a[nxt[i]]);
}
cout << dp[n];
}
int main()
{
std::ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("DIAMOND.inp", "r", stdin);
// freopen("DIAMOND.out", "w", stdout);
int test = 1;
//cin >> test;
while (test--)
{
Input();
solve();
}
return 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... |