Submission #1031674

#TimeUsernameProblemLanguageResultExecution timeMemory
1031674ezzzayGarage (IOI09_garage)C++14
100 / 100
1 ms444 KiB
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define int long long const int N=3e5+5; int pr[N]; int w[N]; int pos[N]; int arr[N]; signed main(){ int n,m; cin>>n>>m; for(int i=1;i<=n;i++){ cin>>pr[i]; } for(int i=1;i<=m;i++){ cin>>w[i]; } set<int>st,ts; for(int i=1;i<=n;i++){ st.insert(i); } queue<int>q; int ans=0; for(int i=0;i<2*m;i++){ int h; cin>>h; if(h>0){ q.push(h); } else{ h*=-1; st.insert(pos[h]); pos[h]=0; } while(!q.empty() and st.size()>0){ int h=q.front(); q.pop(); int x=*st.begin(); st.erase(st.begin()); ans+= w[h]*pr[x]; pos[h]=x; } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...