Submission #1343998

#TimeUsernameProblemLanguageResultExecution timeMemory
1343998realdr4nnekGarage (IOI09_garage)C++20
40 / 100
1 ms436 KiB
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define rep(i, a, b) for (int i = a; i <= b; i++) 
using namespace std;

int N, M, R[101], W[10001];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); 
	cin >> N >> M;
    vi parking(N + 1, 0), cars(M + 1, 0);
    rep(i, 1, N) cin >> R[i];
    rep(i, 1, M) cin >> W[i];
    queue<int> q; int in, ans = 0;
    set<int> avail;
    for (int i = 1; i <= N; i++) avail.insert(i);

    rep(i, 1, 2 * M) {
        cin >> in;
        if (in > 0) {
            if (avail.empty()) {
                q.push(in);
            } else {
                cars[in] = *begin(avail); // set cars to the parking spot
                parking[cars[in]] = i; // set time
                avail.erase(cars[in]); // erase
            }
        } else {
            in = -in;
            ans += W[in] * R[cars[in]];

            if (q.empty()) {
                avail.insert(cars[in]);
            } else {
                int cur = q.front(); q.pop();
                cars[cur] = parking[cars[in]]; // replace with the cars from the queue
                parking[cars[cur]] = i;
            }
            cars[in] = 0;
        }
    }
    cout << ans << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...