# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
220419 | tatyam | Garage (IOI09_garage) | C++17 | 6 ms | 384 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;
#define rep(b) for(int i = 0; i < b; i++)
#define each(i,a) for(auto&& i : a)
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> r(n), w(m);
each(i, r) cin >> i;
each(i, w) cin >> i;
int ans = 0;
vector<int> park(m);
priority_queue<int, vector<int>, greater<int>> space;
queue<int> q;
rep(n) space.push(i);
rep(m * 2){
int a;
cin >> a;
if(a < 0){
int at = park[~a];
if(q.size()){
a = q.front();
q.pop();
park[a] = at;
ans += r[at] * w[a];
}
else space.push(at);
}
else{
a--;
if(space.size()){
int at = space.top();
space.pop();
park[a] = at;
ans += r[at] * w[a];
}
else q.push(a);
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |