제출 #1005586

#제출 시각아이디문제언어결과실행 시간메모리
1005586SpyrosAlivGarage (IOI09_garage)C++14
100 / 100
1 ms524 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("file.in", "r", stdin)
    //freopen("file.out", "w", stdout);
    int n, m; cin >> n >> m;
    int parkCost[n];
    for (auto &i: parkCost) cin >> i;
    int carW[m];
    for (auto &i: carW) cin >> i;
    int ans = 0;
    vector<bool> av(n, true);
    vector<int> slot(m, -1);
    queue<int> q;
    for (int i = 0; i < 2 * m; i++) {
        int x; cin >> x;
        if (x < 0) {
            x = abs(x);
            x--;
            av[slot[x]] = true;
            slot[x] = -1;
            for (int j = 0; j < n; j++) {
                if (q.empty()) break;
                if (!av[j]) continue;
                av[j] = false;
                ans += carW[q.front()] * parkCost[j];
                slot[q.front()] = j;
                q.pop();
            }
        }
        else {
            x--;
            q.push(x);
            for (int j = 0; j < n; j++) {
                if (q.empty()) break;
                if (!av[j]) continue;
                av[j] = false;
                ans += carW[q.front()] * parkCost[j];
                slot[q.front()] = j;
                q.pop();
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...