Submission #501347

#TimeUsernameProblemLanguageResultExecution timeMemory
501347IwanttobreakfreeGarage (IOI09_garage)C++17
100 / 100
2 ms336 KiB
#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 timeMemoryGrader output
Fetching results...