답안 #1034940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034940 2024-07-25T22:50:58 Z ArthuroWich Garage (IOI09_garage) C++17
100 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve() {
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> r(n+1), w(m+1), space(m+1, -1);
    priority_queue<int> available;
    queue<int> cars;
    for (int i = 1; i <= n; i++) {
        cin >> r[i];
        available.push(-i);
    }
    for (int i = 1; i <= m; i++) {
        cin >> w[i];
    }
    for (int i = 0; i < 2*m; i++) {
        int x;
        cin >> x;
        if (x < 0) {
            x = abs(x);
            ans += w[x]*r[space[x]];
            if (!cars.empty()) {
                space[cars.front()] = space[x];
                cars.pop();
            } else {
                available.push(-space[x]);
            }
        } else if (available.empty()) {
            cars.push(x);
        } else {
            space[x] = -available.top();
            available.pop();
        }
    }
    cout << ans << endl;
}
int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    t = 1;
    while(t--) {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct