# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
689747 | zeroesandones | Discharging (NOI20_discharging) | C++17 | 0 ms | 0 KiB |
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;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
#define for(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define ford(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "
#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back
const ll inf = 1e15;
void solve()
{
ll n;
cin >> n;
ll t[n + 1];
for(i, 1, n + 1)
cin >> t[i];
ll dp[n + 1] = {};
for(i, 1, n + 1) {
dp[i] = inf;
ll mx = 0;
ford(j, i, 1) {
mx = max(mx, t[j]);
dp[i] = min(dp[i], dp[j - 1] + (n - j + 1) * mx);
}
}
cout << dp[n] << nl;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(null);
ll t = 1;
// cin >> t;
while (t--)
{
solve();
}
}