# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569411 | Aurora2005 | Garage (IOI09_garage) | C++14 | 2 ms | 340 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>
using namespace std;
int main(){
int N,M;
cin >> N >> M;
vector<long long int> R(N);
for(int i=0;i<N;i++) cin >> R[i];
vector<long long int> W(M);
for(int i=0;i<M;i++) cin >> W[i];
priority_queue<int,vector<int>,greater<int>> que1;
for(int i=0;i<N;i++) que1.push(i);
queue<int> que2;
vector<int> P(M);
long long int ans = 0;
for(int i=0;i<2*M;i++){
int C;
cin >> C;
if(C > 0){
C--;
if(que1.size() == 0) que2.push(C);
else{
int a = que1.top();
que1.pop();
ans += R[a]*W[C];
P[C] = a;
}
}
else{
C++;
C *= -1;
int a = P[C];
que1.push(a);
if(que2.size() > 0){
int b = que1.top();
int c = que2.front();
ans += R[b]*W[c];
que1.pop();
que2.pop();
}
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |