답안 #594886

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
594886 2022-07-13T06:16:41 Z piOOE Dungeon 3 (JOI21_ho_t5) C++17
11 / 100
4000 ms 7332 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, min(t, R[i]) - 1), (ll)u);
            ll buy = max(0ll, mx - cur);
            ans += buy * b[i];
            cur += buy;
            cur -= a[i];
            if (cur < 0) {
                break;
            }
        }
        cout << (cur >= 0 ? ans : -1) << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 492 KB Output is correct
2 Correct 12 ms 468 KB Output is correct
3 Correct 12 ms 460 KB Output is correct
4 Correct 12 ms 484 KB Output is correct
5 Correct 12 ms 456 KB Output is correct
6 Correct 13 ms 460 KB Output is correct
7 Correct 12 ms 468 KB Output is correct
8 Correct 12 ms 468 KB Output is correct
9 Correct 14 ms 604 KB Output is correct
10 Correct 16 ms 460 KB Output is correct
11 Correct 15 ms 468 KB Output is correct
12 Correct 16 ms 500 KB Output is correct
13 Correct 14 ms 488 KB Output is correct
14 Correct 12 ms 456 KB Output is correct
15 Correct 12 ms 492 KB Output is correct
16 Correct 12 ms 524 KB Output is correct
17 Correct 8 ms 468 KB Output is correct
18 Correct 8 ms 524 KB Output is correct
19 Correct 9 ms 480 KB Output is correct
20 Correct 35 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3117 ms 2100 KB Output is correct
2 Correct 3046 ms 3660 KB Output is correct
3 Correct 3122 ms 3968 KB Output is correct
4 Correct 2994 ms 3636 KB Output is correct
5 Correct 3043 ms 3664 KB Output is correct
6 Execution timed out 4054 ms 7332 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4093 ms 4516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 492 KB Output is correct
2 Correct 12 ms 468 KB Output is correct
3 Correct 12 ms 460 KB Output is correct
4 Correct 12 ms 484 KB Output is correct
5 Correct 12 ms 456 KB Output is correct
6 Correct 13 ms 460 KB Output is correct
7 Correct 12 ms 468 KB Output is correct
8 Correct 12 ms 468 KB Output is correct
9 Correct 14 ms 604 KB Output is correct
10 Correct 16 ms 460 KB Output is correct
11 Correct 15 ms 468 KB Output is correct
12 Correct 16 ms 500 KB Output is correct
13 Correct 14 ms 488 KB Output is correct
14 Correct 12 ms 456 KB Output is correct
15 Correct 12 ms 492 KB Output is correct
16 Correct 12 ms 524 KB Output is correct
17 Correct 8 ms 468 KB Output is correct
18 Correct 8 ms 524 KB Output is correct
19 Correct 9 ms 480 KB Output is correct
20 Correct 35 ms 512 KB Output is correct
21 Correct 3117 ms 2100 KB Output is correct
22 Correct 3046 ms 3660 KB Output is correct
23 Correct 3122 ms 3968 KB Output is correct
24 Correct 2994 ms 3636 KB Output is correct
25 Correct 3043 ms 3664 KB Output is correct
26 Execution timed out 4054 ms 7332 KB Time limit exceeded
27 Halted 0 ms 0 KB -