Submission #335399

# Submission time Handle Problem Language Result Execution time Memory
335399 2020-12-12T12:23:00 Z lauran Discharging (NOI20_discharging) C++14
11 / 100
137 ms 14304 KB
#include <bits/stdc++.h>
using namespace std;

const int NMAX = 1e6 + 5;
const long long INF = 1e17;

int n;
int T[NMAX];
long long dp[NMAX];

bool sub3() {
    for (int i = 1; i < n; i++)
        if (T[i] > T[i + 1])
            return 0;
    return 1;
}

bool sub4() {
    for (int i = 1; i < n; i++)
        if (T[i] < T[i + 1])
            return 0;
    return 1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> T[i];

    if (sub4()) {
        long long ans = 0, maxim = 0;
        for (int i = 1; i <= n; i++) {
            maxim = max(maxim, (long long)T[i]);
            ans += maxim;
        }
        cout << ans;
        return 0;
    }

    dp[n] = T[n];

    for (int i = n - 1; i >= 1; i--) {
        int maxT = T[i];
        dp[i] = INF;
        for (int j = i; j <= n; j++) {
            maxT = max(maxT, T[j]);

            dp[i] = min(dp[i], maxT * (n - i + 1) + dp[j + 1]);
        }
    }

    cout << dp[1];

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 116 ms 13932 KB Output is correct
2 Correct 137 ms 13932 KB Output is correct
3 Correct 121 ms 14000 KB Output is correct
4 Correct 118 ms 13892 KB Output is correct
5 Correct 123 ms 14304 KB Output is correct
6 Correct 134 ms 13932 KB Output is correct
7 Correct 115 ms 13964 KB Output is correct
8 Correct 122 ms 13932 KB Output is correct
9 Correct 116 ms 13932 KB Output is correct
10 Correct 117 ms 14020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -