# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535007 | devariaota | Garage (IOI09_garage) | C++17 | 3 ms | 332 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
typedef long long ll;
using namespace std;
ll n, m, ans;
ll car[2005], park[2005], rate[105];
queue<ll>q;
priority_queue<int, vector<int>, greater<int> >pq;
int main(){
cin >> n >> m;
for(int i = 1; i <= n; i++){
ll rates; cin >> rates;
pq.push(i);
rate[i] = rates;
}
for(int i = 1; i <= m; i++){
cin >> car[i];
}
for(int i = 1; i <= 2*m; i++){
ll f; cin >> f;
if(f > 0){
if(!pq.empty()){
ans += car[f]*rate[pq.top()];
park[f] = pq.top();
pq.pop();
}
else{
q.push(f);
}
}
else{
f*=-1;
pq.push(park[f]);
if(!q.empty()){
ll w = car[q.front()];
ans += w*rate[pq.top()];
park[q.front()] = pq.top();
pq.pop();
q.pop();
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |