Submission #1104245

#TimeUsernameProblemLanguageResultExecution timeMemory
1104245melody_rulesGarage (IOI09_garage)C++17
100 / 100
2 ms508 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int n=0; int m=0; int a=0; int b=0; int i=0; cin>>n>>m; vector<int> vec(n); //Price vector<int> veco(m); //Weight queue<int> q; //Queue vector<pair<int, int>> stat(m, {-1, -1}); set<pair<int, int>> s; for(i=0;i<n;i++) { cin>>a; vec.at(i) = a; s.insert({i, a}); } for(i=0;i<m;i++) { cin>>a; veco.at(i) = a; } for(i=0;i<(2*m);i++) { cin>>a; if(a > 0) { if(s.empty()) q.push(a); else { auto it = s.begin(); b += veco.at(a-1)*((*it).second); stat.at(a-1) = (*it); s.erase(it); } } else { a *= -1; if(!q.empty()) { stat.at(q.front()-1) = stat.at(a-1); b += veco.at(q.front() - 1)*(stat.at(q.front() - 1).second); q.pop(); } else s.insert(stat.at(a-1)); stat.at(a-1) = {-1, -1}; } } cout<<b<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...