# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
853945 | tue147 | Garage (IOI09_garage) | C++14 | 2 ms | 476 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 n,m;
unsigned long long sum = 0;
int main(){
ios_base::sync_with_stdio;
cin.tie(0);
cin >> n >> m;
int r[n];
int w[m];
set<int> s;
unordered_map<int, int> store;
queue<int> q;
int temp;
for (int i=0; i< n; i++){
cin >> r[i];
s.insert(i);
}
for (int i=0; i< m; i++){
cin >> w[i];
}
for (int i=0; i< 2*m; i++){
cin >> temp;
if (temp > 0){
if (!s.empty()){
set<int>::iterator ptr = s.begin();
sum += r[*ptr] * w[temp-1];
store[temp] = *ptr;
s.erase(ptr);
}
else{
q.push(temp);
}
}
else{
temp = -temp;
int place = store[temp];
s.insert(place);
store.erase(temp);
}
while (!q.empty() && !s.empty()){
temp = q.front();
q.pop();
set<int>::iterator ptr = s.begin();
sum += r[*ptr] * w[temp-1];
store[temp] = *ptr;
s.erase(ptr);
}
}
cout << sum;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |