# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
956417 | emad234 | Garage (IOI09_garage) | C++17 | 2 ms | 2648 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 ll long long
#define F first
#define S second
#define pii pair<ll, ll>
const ll mod = 1e9 + 7;
const ll mxN = 1e5 + 5;
using namespace std;
ll val[mxN];
ll w[mxN];
ll pk[mxN];
int main(){
int n,m;
cin >>n>>m;
priority_queue<int,vector<int>,greater<int>>q;
for(int i = 1;i <= n;i++){
cin >>val[i];
q.push(i);
}
queue<int>car;
ll ans = 0;
for(int i = 1;i <= m;i++) cin >>w[i];
for(int i = 0;i < m * 2;i++){
int x;
cin >>x;
if(x > 0){
if(q.size()){
ans += val[q.top()] * w[x];
pk[x] = q.top();
q.pop();
}else{
car.push(x);
}
}else{
x *= -1;
if(car.size()){
ans += w[car.front()] * val[pk[x]];
pk[car.front()] = pk[x];
car.pop();
}else{
q.push(pk[x]);
}
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |