답안 #653002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653002 2022-10-25T11:40:26 Z Stickfish Dungeon 3 (JOI21_ho_t5) C++17
11 / 100
4000 ms 6368 KB
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
using ll = long long;

const int MAXN = 2e5 + 123;
ll eng[MAXN];
ll cost[MAXN];

ll get_ans(int l, int r, int mxeng) {
    deque<pair<ll, ll>> dq;
    ll eng_total = 0;
    ll ans = 0;
    for (int i = l; i < r; ++i) {
        while (dq.size() && dq.back().first >= cost[i]) {
            eng_total -= dq.back().second;
            dq.pop_back();
        }
        if (eng_total < mxeng)
            dq.push_back({cost[i], mxeng - eng_total});
        eng_total = mxeng;
        if (eng[i] > eng_total) {
            return -1;
        }
        ll eng_need = eng[i];
        while (eng_need > 0) {
            if (eng_need >= dq.front().second) {
                eng_need -= dq.front().second;
                ans += dq.front().first * dq.front().second;
                eng_total -= dq.front().second;
                dq.pop_front();
            } else {
                dq.front().second -= eng_need;
                ans += dq.front().first * eng_need;
                eng_total -= eng_need;
                eng_need = 0;
            }
        }
    }
    return ans;
}

signed main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> eng[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> cost[i];
    }
    while (m--) {
        int l, r, mxeng;
        cin >> l >> r >> mxeng;
        --l, --r;
        cout << get_ans(l, r, mxeng) << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 460 KB Output is correct
2 Correct 61 ms 504 KB Output is correct
3 Correct 32 ms 460 KB Output is correct
4 Correct 57 ms 452 KB Output is correct
5 Correct 45 ms 492 KB Output is correct
6 Correct 33 ms 476 KB Output is correct
7 Correct 57 ms 488 KB Output is correct
8 Correct 42 ms 516 KB Output is correct
9 Correct 32 ms 448 KB Output is correct
10 Correct 57 ms 456 KB Output is correct
11 Correct 50 ms 468 KB Output is correct
12 Correct 31 ms 496 KB Output is correct
13 Correct 48 ms 476 KB Output is correct
14 Correct 30 ms 416 KB Output is correct
15 Correct 35 ms 468 KB Output is correct
16 Correct 43 ms 516 KB Output is correct
17 Correct 39 ms 456 KB Output is correct
18 Correct 46 ms 464 KB Output is correct
19 Correct 24 ms 448 KB Output is correct
20 Correct 87 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 2924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4046 ms 6368 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 460 KB Output is correct
2 Correct 61 ms 504 KB Output is correct
3 Correct 32 ms 460 KB Output is correct
4 Correct 57 ms 452 KB Output is correct
5 Correct 45 ms 492 KB Output is correct
6 Correct 33 ms 476 KB Output is correct
7 Correct 57 ms 488 KB Output is correct
8 Correct 42 ms 516 KB Output is correct
9 Correct 32 ms 448 KB Output is correct
10 Correct 57 ms 456 KB Output is correct
11 Correct 50 ms 468 KB Output is correct
12 Correct 31 ms 496 KB Output is correct
13 Correct 48 ms 476 KB Output is correct
14 Correct 30 ms 416 KB Output is correct
15 Correct 35 ms 468 KB Output is correct
16 Correct 43 ms 516 KB Output is correct
17 Correct 39 ms 456 KB Output is correct
18 Correct 46 ms 464 KB Output is correct
19 Correct 24 ms 448 KB Output is correct
20 Correct 87 ms 460 KB Output is correct
21 Execution timed out 4051 ms 2924 KB Time limit exceeded
22 Halted 0 ms 0 KB -