Submission #594883

# Submission time Handle Problem Language Result Execution time Memory
594883 2022-07-13T06:10:16 Z piOOE Dungeon 3 (JOI21_ho_t5) C++17
0 / 100
4000 ms 7504 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    vector<ll> pref(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        pref[i] = (i ? pref[i - 1] : 0) + a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    vector<int> R(n, n), stk;
    for (int i = 0; i < n; ++i) {
        while (!stk.empty() && b[stk.back()] >= b[i]) {
            R[stk.back()] = i;
            stk.pop_back();
        }
        stk.push_back(i);
    }
    auto get = [&](int l, int r) {
        return pref[r] - (l ? pref[l - 1] : 0);
    };
    while (m--) {
        int s, t, u;
        cin >> s >> t >> u;
        --s, --t;
        ll ans = 0, cur = 0;
        for (int i = s; i < t; ++i) {
            ll mx = min(get(i, R[i] - 1), (ll)u);
            ll buy = mx - cur;
            ans += buy * b[i];
            cur += buy;
            cur -= a[i];
            if (cur < 0) {
                break;
            }
        }
        cout << (cur >= 0 ? ans : -1) << '\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2218 ms 3564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4045 ms 7504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 496 KB Output isn't correct
2 Halted 0 ms 0 KB -