Submission #989797

# Submission time Handle Problem Language Result Execution time Memory
989797 2024-05-28T19:50:41 Z aaaaaarroz Garage (IOI09_garage) C++17
100 / 100
2 ms 436 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> rate(n);
    for (int i = 0; i < n; i++) {
        cin >> rate[i];
    }
    vector<int> weight(m);
    for (int i = 0; i < m; i++) {
        cin >> weight[i];
    }
    queue<int> cola;
    vector<bool> ocupado(n, false);
    map<int, int> espacio;
    int ganancia = 0;
    int q = 2 * m;
    while (q--) {
        int v;
        cin >> v;
        if (v >= 1) {
            v--;
            int peso = weight[v];
            bool encontrado = false;
            for (int i = 0; i < n; i++) {
                if (!ocupado[i]) {
                    ocupado[i] = true;
                    espacio[v] = i;
                    ganancia += (rate[i] * peso);
                    encontrado = true;
                    break;
                }
            }
            if (!encontrado) {
                cola.push(v);
            }
        } else {
            v = -v - 1;
            int i = espacio[v];
            ocupado[i] = false;
            if (!cola.empty()) {
                int nextCar = cola.front();
                cola.pop();
                int peso = weight[nextCar];
                ocupado[i] = true;
                espacio[nextCar] = i;
                ganancia += (rate[i] * peso);
            }
        }
    }
    cout << ganancia << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 436 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct