Submission #1323969

#TimeUsernameProblemLanguageResultExecution timeMemory
1323969kasamchiGarage (IOI09_garage)C++20
100 / 100
1 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N, M;
    cin >> N >> M;

    vector<int> R(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> R[i];
    }

    vector<int> W(M + 1);
    for (int i = 1; i <= M; i++) {
        cin >> W[i];
    }

    vector<int> space(N + 1);
    long long ans = 0;
    queue<int> quu;
    for (int i = 0; i < M + M; i++) {
        int x;
        cin >> x;
        if (x > 0) {
            quu.push(x);
        } else {
            for (int j = 1; j <= N; j++) {
                if (space[j] == -x) {
                    space[j] = 0;
                }
            }
        }
        while (!quu.empty()) {
            x = quu.front();
            bool ok = false;
            for (int j = 1; j <= N && !ok; j++) {
                if (space[j] == 0) {
                    space[j] = x;
                    ans += W[x] * R[j];
                    quu.pop();
                    break;
                }
            }
            if (!ok) {
                break;
            }
        }
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...