Submission #1306742

#TimeUsernameProblemLanguageResultExecution timeMemory
1306742liangjeremyGarage (IOI09_garage)C++20
100 / 100
2 ms576 KiB
#include<bits/stdc++.h> #include<bits/extc++.h> #define fi first #define se second #define int long long using namespace std; //using namespace __gnu_pbds; using db=double; using ll=int64_t; using sint=__int128; using lb=long double; mt19937 rng(random_device{}()); int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; vector<int>r(n+1); vector<int>w(m+1); for(int i=1; i<=n; i++){ cin>>r[i]; } for(int i=1; i<=m; i++){ cin>>w[i]; } priority_queue<int,vector<int>,greater<int>>pq; queue<int>q; int ans=0; vector<int>a(m+1,-1); for(int i=1; i<=n; i++){ pq.push(i); } for(int i=1; i<=2*m; i++){ int x; cin>>x; if(x>=0){ if(pq.size()){ a[x]=pq.top(); pq.pop(); ans+=w[x]*r[a[x]]; }else q.push(x); }else{ x*=-1; if(a[x]!=-1){ int p=a[x]; pq.push(p); if(q.size()){ int node=q.front(); q.pop(); a[node]=pq.top(); pq.pop(); ans+=w[node]*r[a[node]]; } } } } cout<<ans<<'\n'; } /* Overhead the albatross hangs motionless upon the air And deep beneath the rolling waves in labyrinths of coral caves The echo of a distant time comes willowing across the sand And everything is green and submarine And no one showed us to the land And no one knows the wheres or whys But something stirs and something tries And starts to climb towards the light */
#Verdict Execution timeMemoryGrader output
Fetching results...