Submission #535007

#TimeUsernameProblemLanguageResultExecution timeMemory
535007devariaotaGarage (IOI09_garage)C++17
100 / 100
3 ms332 KiB
#include <bits/stdc++.h> #define pb push_back #define fi first #define se second typedef long long ll; using namespace std; ll n, m, ans; ll car[2005], park[2005], rate[105]; queue<ll>q; priority_queue<int, vector<int>, greater<int> >pq; int main(){ cin >> n >> m; for(int i = 1; i <= n; i++){ ll rates; cin >> rates; pq.push(i); rate[i] = rates; } for(int i = 1; i <= m; i++){ cin >> car[i]; } for(int i = 1; i <= 2*m; i++){ ll f; cin >> f; if(f > 0){ if(!pq.empty()){ ans += car[f]*rate[pq.top()]; park[f] = pq.top(); pq.pop(); } else{ q.push(f); } } else{ f*=-1; pq.push(park[f]); if(!q.empty()){ ll w = car[q.front()]; ans += w*rate[pq.top()]; park[q.front()] = pq.top(); pq.pop(); q.pop(); } } } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...