Submission #233382

#TimeUsernameProblemLanguageResultExecution timeMemory
233382vioalbertGarage (IOI09_garage)C++14
100 / 100
7 ms384 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 105, M = 2005; int n, m; int cost[N], used[M], weight[M]; priority_queue<int, vector<int>, greater<int>> avail; queue<int> q; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for(int i = 1; i <= n; i++) { cin >> cost[i]; avail.push(i); } for(int i = 1; i <= m; i++) cin >> weight[i]; ll ans = 0; for(int c = 0; c < 2*m; c++) { int x; cin >> x; if(x > 0) { if(avail.empty()) q.push(x); else used[x] = avail.top(), avail.pop(); } else { x *= -1; ans += 1ll*cost[used[x]]*weight[x]; if(!q.empty()) used[q.front()] = used[x], q.pop(); else avail.push(used[x]); } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...