# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
73777 | TuGSGeReL | Garage (IOI09_garage) | C++14 | 5 ms | 960 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 ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back
#define ss second
#define ff first
#define ext exit(0)
using namespace std;
ll n,m,i,cst[101],w[2001],pos[2001],x,ans;
priority_queue<int>pq;
deque<int>v;
int main (){
cin>>n>>m;
for(i=1;i<=n;i++){
cin>>cst[i];
pq.push(-i);
}
for(i=1;i<=m;i++) cin>>w[i];
for(i=1;i<=2*m;i++){
cin>>x;
if(x>0){
if(v.size()) v.pub(x);
else {
if(pq.size()==0) v.pub(x);
else{
ll o=-pq.top();
pos[x]=o;
ans+=w[x]*cst[o];
pq.pop();
}
}
}
else{
pq.push(-pos[-x]);
if(v.size()){
ll o=-pq.top();
pos[v.front()]=o;
ans+=w[v.front()]*(cst[o]);
pq.pop();
v.pop_front();
}
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |