제출 #1260401

#제출 시각아이디문제언어결과실행 시간메모리
1260401kawhietGarage (IOI09_garage)C++20
100 / 100
1 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    vector<bool> is(n);
    vector<int> id(m + 1);
    queue<int> q;
    int ans = 0;
    for (int i = 0; i < 2 * m; i++) {
        int x;
        cin >> x;
        if (x > 0) {
            bool can = 0;
            for (int j = 0; j < n; j++) {
                if (!is[j]) {
                    can = 1;
                    is[j] = 1;
                    id[x] = j;
                    ans += b[x] * a[j];
                    break;
                }
            }
            if (!can) {
                q.push(x);
            }
        }
        else {
            x = -x;
            is[id[x]] = 0;
            id[x] = 0;
            if (q.empty()) continue;
            int y = q.front(); q.pop();
            for (int j = 0; j < n; j++) {
                if (!is[j]) {
                    is[j] = 1;
                    id[y] = j;
                    ans += b[y] * a[j];
                    break;
                }
            }
        }
    }
    cout << ans << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...