| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1277840 | ducdev | Discharging (NOI20_discharging) | C++17 | 1097 ms | 4896 KiB | 
// Author: 4uckd3v - Nguyen Cao Duc
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1e6;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
int n;
int a[MAX_N + 5];
pair<ll, ll> dp[MAX_N + 5];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if (fopen("MAIN.INP", "r")) {
        freopen("MAIN.INP", "r", stdin);
        freopen("MAIN.OUT", "w", stdout);
    };
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    };
    for (int i = 1; i <= n; i++) {
        dp[i].first = dp[i].second = INF;
        int mx = 0;
        for (int j = i; j >= 1; j--) {
            mx = max(mx, a[j]);
            dp[i] = min(dp[i], {dp[j - 1].first + (dp[j - 1].second + mx) * (i - j + 1),
                                (dp[j - 1].second + mx)});
        };
    };
    cout << dp[n].first << '\n';
};
Compilation message (stderr)
| # | 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... | ||||
