# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1104245 | melody_rules | Garage (IOI09_garage) | C++17 | 2 ms | 508 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 int long long
using namespace std;
signed main() {
int n=0;
int m=0;
int a=0;
int b=0;
int i=0;
cin>>n>>m;
vector<int> vec(n); //Price
vector<int> veco(m); //Weight
queue<int> q; //Queue
vector<pair<int, int>> stat(m, {-1, -1});
set<pair<int, int>> s;
for(i=0;i<n;i++) {
cin>>a;
vec.at(i) = a;
s.insert({i, a});
}
for(i=0;i<m;i++) {
cin>>a;
veco.at(i) = a;
}
for(i=0;i<(2*m);i++) {
cin>>a;
if(a > 0) {
if(s.empty())
q.push(a);
else {
auto it = s.begin();
b += veco.at(a-1)*((*it).second);
stat.at(a-1) = (*it);
s.erase(it);
}
}
else {
a *= -1;
if(!q.empty()) {
stat.at(q.front()-1) = stat.at(a-1);
b += veco.at(q.front() - 1)*(stat.at(q.front() - 1).second);
q.pop();
}
else
s.insert(stat.at(a-1));
stat.at(a-1) = {-1, -1};
}
}
cout<<b<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |