# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74490 | JustInCase | Garage (IOI09_garage) | C++17 | 4 ms | 856 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>
#define endl '\n'
using namespace std;
const int32_t MAX_N = 100;
const int32_t MAX_M = 2000;
int32_t rates[MAX_N + 5], weights[MAX_M + 5], placeOf[MAX_M + 5];
set< int32_t > emptyPlaces;
queue< int32_t > waitingCars;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int32_t n, m;
cin >> n >> m;
for(int32_t i = 0; i < n; i++) {
cin >> rates[i];
emptyPlaces.insert(i);
}
for(int32_t i = 0; i < m; i++) {
cin >> weights[i];
}
int32_t ans = 0;
for(int32_t i = 0; i < 2 * m; i++) {
int32_t ind;
cin >> ind;
if(ind < 0) {
ind = -ind;
emptyPlaces.insert(placeOf[ind]);
if(!waitingCars.empty()) {
int32_t ind = waitingCars.front();
waitingCars.pop();
placeOf[ind] = *emptyPlaces.begin();
emptyPlaces.erase(emptyPlaces.begin());
ans += rates[placeOf[ind]] * weights[ind - 1];
}
}
else {
if(!emptyPlaces.empty()) {
placeOf[ind] = *emptyPlaces.begin();
emptyPlaces.erase(emptyPlaces.begin());
ans += rates[placeOf[ind]] * weights[ind - 1];
}
else {
waitingCars.push(ind);
}
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |