# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501347 | Iwanttobreakfree | Garage (IOI09_garage) | C++17 | 2 ms | 336 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 <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
int n,m,x,ans=0;
cin>>n>>m;
vector<int> r(n),w(m),park(m,-1);
for(int& i:r)cin>>i;
for(int& i:w)cin>>i;
queue<int> q;
priority_queue<int> pq;
for(int i=0;i<n;i++)pq.push(-i);
for(int i=0;i<2*m;i++){
cin>>x;
if(x<0){
x*=-1;
x--;
pq.push(-park[x]);
ans+=w[x]*r[park[x]];
park[x]=-1;
if(!q.empty()){
park[q.front()]=-pq.top();
pq.pop();
q.pop();
}
}
else{
x--;
if(pq.empty())q.push(x);
else{
park[x]=-pq.top();
pq.pop();
}
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |