제출 #372896

#제출 시각아이디문제언어결과실행 시간메모리
372896apostoldaniel854Garage (IOI09_garage)C++14
45 / 100
2 ms492 KiB
#include <bits/stdc++.h>

using namespace std;
const int MAX_N = 100, MAX_M = 1000;
using ll = long long;

bool taken[1 + MAX_N];
bool wasted[1 + MAX_M];
int parked_at[1 + MAX_N];
int main () {
    ios::sync_with_stdio (false);
    cin.tie (0); cout.tie (0);
    int n, m;
    cin >> n >> m;
    vector <int> r (n + 1), w (m + 1);
    for (int i = 1; i <= n; i++)
        cin >> r[i];
    for (int i = 1; i <= m; i++)
        cin >> w[i];
    queue <int> car_line;
    ll ans = 0;
    for (int i = 1; i <= 2 * m; i++) {
        int t;
        cin >> t;
        if (t > 0)
            car_line.push (t);
        else {
            t = -t;
            wasted[t] = true;
            if (parked_at[t])
                taken[parked_at[t]] = false;
        }
        while (car_line.size () && wasted[car_line.front ()])
            car_line.pop ();
        if (car_line.size ()) {
            int space = 1;
            while (taken[space])
                space++;
            if (space <= n) {
                taken[space] = true;
                parked_at[car_line.front ()] = space;
                ans += w[car_line.front ()] * r[space];
                car_line.pop ();
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...