제출 #1128955

#제출 시각아이디문제언어결과실행 시간메모리
1128955MathiasGarage (IOI09_garage)C++20
100 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define fi first #define sc second #define vi vector<int> #define pii pair<int,int> #define vpi vector<pair<int,int> > #define mp make_pair const ll MOD1 = 1e9+7; const ll MOD2 = 998244353; const ll MOD3 = 1e9+93; const ll MOD4 = 1e9+97; const ll p1 = 1e9+87; const ll p2 = 1e9+9; const int INF = 1e9+7; const int BASE = 1<<20; const int LOG = 20; const int ALF = 27; const int MAXN = 1e6+7; const int MAXNN = 1e3+7; int t[MAXN],w[MAXN],l[MAXN]; pii p[MAXN]; set<pair<int,int>>s; queue<int>q; void solve(){ int n,m,x; pair<int,int>xd; ll cost=0; cin>>n>>m; for(int i=1;i<=n;i++) cin>>x, s.insert({i,x}); for(int i=1;i<=m;i++) cin>>w[i]; for(int i=1;i<=2*m;i++){ cin>>x; if(x>0){ if(s.size()>0){ auto it=s.begin(); xd=*it; cost+=w[x]*xd.sc; p[x]=xd; s.erase(s.begin()); } else q.push(x); } else{ x=-x; l[x]=1; if(p[x].fi!=0) s.insert(p[x]); while(q.size() and s.size()){ x=q.front(), q.pop(); if(l[x]==1) continue; auto it=s.begin(); xd=*it; cost+=w[x]*xd.sc; p[x]=xd; s.erase(s.begin()); } } } cout<<cost<<'\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt=1; while(tt--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...