Submission #1225044

#TimeUsernameProblemLanguageResultExecution timeMemory
1225044takoshanavaGarage (IOI09_garage)C++20
100 / 100
2 ms328 KiB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fs first
#define sc second
using namespace std;

const int N = 105, M = 2005;
int r[N], w[M], cur[M];
bool fr[N];
int n, m, ans;

queue<int> q;

signed main() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> r[i];
    for (int i = 1; i <= m; i++) cin >> w[i]; 

    for (int i = 1; i <= n; i++) fr[i] = true;

    int k = 2 * m;
    while (k--) {
        int x;
        cin >> x;
        if (x > 0) {
            bool parked = false;
            for (int i = 1; i <= n; i++) {
                if (fr[i]) {
                    fr[i] = false;
                    cur[x] = i;
                    ans += r[i] * w[x]; 
                    parked = true;
                    break;
                }
            }
            if (!parked) q.push(x);
        } else {
            x = -x;
            int slot = cur[x];
            fr[slot] = true;
            cur[x] = 0;
            if (!q.empty()) {
                int next = q.front(); q.pop();
                fr[slot] = false;
                cur[next] = slot;
                ans += r[slot] * w[next];
            }
        }
    }

    cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...