# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
964229 | anango | Garage (IOI09_garage) | C++17 | 4 ms | 500 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 int long long
using namespace std;
signed main() {
int n,m;
cin >> n >> m;
int total = 0;
vector<int> rates(n);
vector<int> parkedposcar(n,-1);
vector<int> parkedcarpos(m,-1);
vector<int> weights(m);
set<int> available;
for (int i=0; i<n; i++) {
available.insert(i);
}
for (int i=0; i<n; i++) {
int x;
cin >> x;
rates[i] = x;
}
for (int i=0; i<m; i++) {
int x;
cin >> x;
weights[i] = x;
}
deque<int> Q;
for (int e=0; e<2*m; e++) {
// cout << "doing" <<" " << e << " " << parkedcarpos[2] << " " << parkedcarpos[0] << endl;
//cout << "queue" <<" ";
int x;
for (auto i:Q) {
// cout << i <<" ";
}
// cout << endl;
cin >> x;
if (x>0) {
x--;
if (!available.size()) {
Q.push_front(x);
}
else {
int minpos = *available.begin();
available.erase(minpos);
parkedcarpos[x] = minpos;
parkedposcar[minpos] = x;
total+=rates[minpos]*weights[x];
}
}
else {
x=-x;
x--;
assert(parkedcarpos[x]!=-1);
available.insert(parkedcarpos[x]);
parkedcarpos[x] = -1;
while (Q.size() && available.size()) {
int minpos = *available.begin();
//cout << "pop " << Q.back() << " " << rates[minpos]*weights[Q.back()] << endl;
available.erase(minpos);
parkedcarpos[Q.back()] = minpos;
parkedposcar[minpos] = Q.back();
total+=rates[minpos]*weights[Q.back()];
Q.pop_back();
}
}
}
cout << total << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |