제출 #1224796

#제출 시각아이디문제언어결과실행 시간메모리
1224796redoGarage (IOI09_garage)C++20
100 / 100
1 ms328 KiB
#include <bits/stdc++.h> #define endl '\n' #define all(a) (a).begin(), (a).end() #define vi vector<int> #define int long long int using namespace std; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin>>n>>m; vi ra(n); vi we(m); vi mapa(m); queue<int> fila; priority_queue<int> ava; for(int i = 0; i<n; i++) { cin>>ra[i]; ava.push(- (i + 1)); } for(auto &i: we) cin>>i; int q; int gana = 0; for(int _ = 0; _<2 * m; _++) { cin>>q; if(q > 0) { if(!ava.empty()) { gana += we[q-1] * ra[-ava.top() - 1]; mapa[q - 1] = -ava.top() - 1; ava.pop(); } else { fila.push(q); } } else { if(!fila.empty()) { gana += we[fila.front() - 1] * ra[mapa[-q - 1]]; mapa[fila.front() - 1] = mapa[-q-1]; fila.pop(); } else { ava.push(-(mapa[-q - 1] + 1)); } } } cout<<gana<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...