Submission #73777

#TimeUsernameProblemLanguageResultExecution timeMemory
73777TuGSGeReLGarage (IOI09_garage)C++14
100 / 100
5 ms960 KiB
#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 timeMemoryGrader output
Fetching results...