답안 #1082754

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1082754 2024-09-01T13:04:47 Z toast12 Garage (IOI09_garage) C++14
100 / 100
4 ms 456 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> rates(n), weights(m);
    for (int i = 0; i < n; i++) {
        cin >> rates[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> weights[i];
    }
    multiset<int> available;
    for (int i = 0; i < n; i++) {
        available.insert(i);
    }
    map<int, int> lots;
    queue<int> q;
    long long ans = 0;
    for (int i = 0; i < 2*m; i++) {
        int car;
        cin >> car;
        if (car < 0) {
            car *= -1;
            car--;
            if (!q.empty()) {
                int car2 = q.front();
                lots[car2] = lots[car];
                ans += weights[car2]*rates[lots[car2]];
                q.pop();
            }
            else {
                available.insert(lots[car]);
            }
            lots[car] = 0;
            continue;
        }
        car--;
        if (available.empty()) {
            q.push(car);
            continue;
        }
        int lot = *(available.begin());
        ans += weights[car]*rates[lot];
        lots[car] = lot;
        available.erase(lot);
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 432 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 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 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 456 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 344 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 4 ms 344 KB Output is correct