Submission #495532

#TimeUsernameProblemLanguageResultExecution timeMemory
495532PiejanVDCGarage (IOI09_garage)C++17
100 / 100
3 ms332 KiB
#include <bits/stdc++.h> using namespace std; signed main() { int n,m; cin>>n>>m; vector<int>s(n); for(auto &z : s) cin>>z; vector<int>w(m); for(auto &z : w) cin>>z; int64_t ans = 0LL; vector<int>place(m); priority_queue<int>pq; for(int i = 0 ; i < n ; i++) pq.push(-i); queue<int>line; for(int i = 0 ; i < 2*m ; i++) { while(!line.empty()) { if(pq.empty()) break; place[line.front()] = -pq.top(); ans += (s[-pq.top()]) * (w[line.front()]); pq.pop(); line.pop(); } int x; cin>>x; if(x > 0) { x--; line.push(x); } else { x = -x; x--; pq.push(-(place[x])); } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...