Submission #292433

#TimeUsernameProblemLanguageResultExecution timeMemory
292433Ruba_KGarage (IOI09_garage)C++14
100 / 100
2 ms512 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5e5 + 1 ; #define ll long long int main() {ios_base::sync_with_stdio(false);cin.tie(0); int n , m ; cin >> n >> m ; int cost[n + 1] , cars[m + 1]; set<int>av; for(int i = 1 ; i <= n ; i ++){ cin >> cost[i]; av.insert(i); } for(int i = 1 ; i <= m ; i ++) cin >> cars[i]; ll ans = 0 ; queue<int>q ; map<int , int >mp ; for(int i = 0 ; i < m * 2 ; i ++){ int a ; cin >> a ; if(a < 0){ av.insert(mp[-a]); int b = *av.begin(); if(q.size()){ int f = q.front(); q.pop(); ans += cost[b] * 1ll * cars[f]; av.erase(b); mp[f] = b ; } } else{ q.push(a); if(av.empty()) continue ; int b = *av.begin(); int f = q.front(); q.pop(); ans += 1ll * cost[b] * cars[f]; av.erase(b); mp[f] = b ; } } cout << ans ; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...