# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
715369 | Toxtaq | Garage (IOI09_garage) | C++17 | 3 ms | 340 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 spaces, cars;
long long result = 0;
cin >> spaces >> cars;
vector<int>rate(spaces + 1), weights(cars + 1);
for(int i = 1;i <= spaces;++i)cin >> rate[i];
for(int i = 1;i <= cars;++i)cin >> weights[i];
vector<int>parking(spaces + 1);
queue<int>q;
for(int i = 0;i < 2 * cars;++i){
int car;
bool parked = false;
cin >> car;
if(car > 0){
for(int j = 1;j <= spaces;++j){
if(!parking[j]){
parking[j] = car;
result += weights[car] * rate[j];
parked = true;
break;
}
}
if(!parked){
q.push(car);
}
}
else{
for(int j = 1;j <= spaces;++j){
if(-car == parking[j]){
parking[j] = 0;
break;
}
}
if(!q.empty()){
int cur = q.front();
q.pop();
for(int j = 1;j <= spaces;++j){
if(!parking[j]){
parking[j] = cur;
result += weights[cur] * rate[j];
break;
}
}
}
}
}
cout << result;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |