Submission #684144

#TimeUsernameProblemLanguageResultExecution timeMemory
684144Hacv16Garage (IOI09_garage)C++17
100 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 2e5 + 15; const int INF = 0x3f3f3f3f; int n, m, rev, r[MAX], w[MAX], spot[MAX]; set<int> s; queue<int> q; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> r[i]; s.insert(i); } for(int i = 1; i <= m; i++) cin >> w[i]; for(int i = 1; i <= 2 * m; i++){ int car; cin >> car; if(car < 0) s.insert(spot[-car]); else q.push(car); while(s.size()){ if(q.empty()) break; int cur = q.front(); q.pop(); int curSpot = *(s.begin()); s.erase(s.begin()); spot[cur] = curSpot; rev += w[cur] * r[curSpot]; } } cout << rev << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...