제출 #761225

#제출 시각아이디문제언어결과실행 시간메모리
761225BlagojGarage (IOI09_garage)C++17
100 / 100
2 ms340 KiB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

int main() {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int n, m, t;
    cin >> n >> m;
    t = n;
    int r[n], w[m], went[m];
    for (int i = 0; i < n; i++) cin >> r[i];
    for (int i = 0; i < m; i++) cin >> w[i];
    queue<int> q;
    bool full[n];
    memset(full, 0, sizeof(full));
    ll ans = 0;
    for (int i = 0; i < 2 * m; i++) {
        int c;
        cin >> c;
        if (c > 0) {
            c--;
            if (n == 0) {
                q.push(c);
                continue;
            }
            for (int j = 0; j < t; j++) {
                if (full[j]) continue;
                ans += w[c] * r[j];
                full[j] = 1;
                went[c] = j;
                n--;
                break;
            }
        }
        else {
            c *= -1;
            c--;
            n++;
            full[went[c]] = 0;
            while (n > 0 && q.size() > 0) {
                int f = q.front();
                q.pop();
                for (int j = 0; j < t; j++) {
                    if (full[j]) continue;
                    ans += w[f] * r[j];
                    full[j] = 1;
                    went[f] = j;
                    n--;
                    break;
                }
            }
        }
    }
    cout << ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...