# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
989797 | aaaaaarroz | Garage (IOI09_garage) | C++17 | 2 ms | 436 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |