Submission #370030

# Submission time Handle Problem Language Result Execution time Memory
370030 2021-02-23T02:05:18 Z danielcm585 Discharging (NOI20_discharging) C++14
0 / 100
120 ms 11372 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

typedef long long ll;
typedef pair<int,int> ii;

const int N = 1e6;
int n;
ll t[N+2], h[N+2];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
    }
    stack<ll> st;
    st.push(0);
    ll ans = 0, maxi = 0;
    for (int i = 1; i <= n; i++) {
        if (t[i] > maxi) {
            // cout << i << " -> " << (t[i]-t[ls])*(n-ls+1) << ' ' << t[i]*(n-i+1) << '\n';
            int cost = t[i]*(n-i+1);
            while (!st.empty() && (t[i]-t[st.top()])*(n-st.top()+1) < cost) {
                cost = (t[i]-t[st.top()])*(n-st.top()+1);
                st.pop();
            }
            ans += cost;
            st.push(i);
            maxi = t[i];
            // if (ls && (t[i]-t[ls])*(n-ls+1) < t[i]*(n-i+1)) {
            //     ans += (t[i]-t[ls])*(n-ls+1);
            //     t[ls] = t[i];
            // }
            // else {
            //     ans += t[i]*(n-i+1);
            //     ls = i;
            // }
        }
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 120 ms 11372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -