# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
732791 | Roman70 | Garage (IOI09_garage) | C++17 | 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>
#define forn(i,n) for(int i = 0;i<n;i++)
#define ll long long
#define pb push_back
#define sz(a) a.size()
using namespace std;
struct cmp{
bool operator()(const int a, const int b){
return a > b;
}
};
void solve()
{
int n,m;
cin >> n >> m;
int rate[n];
int w[m];
priority_queue<int,vector<int>,cmp>loturi;
int park[m];
forn(i,n){
int cost;
cin >> cost;
loturi.push(cost);
}
forn(i,m){
cin >> w[i];
}
queue<int>c;
int p = 0;
forn(i,2*m){
int car;
cin >> car;
if(car > 0){
if(loturi.size()){
int pret = loturi.top();
p += (pret * w[car-1]);
loturi.pop();
park[car-1] = pret;
}
else c.push(car-1);
}
else{
car*=(-1);
if(c.size()){
int cr = c.front();
c.pop();
p += (park[car-1] * w[cr]);
park[cr] = park[car-1];
}
else loturi.push(park[car-1]);
}
}
cout<<p;
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
// freopen("num.txt","r",stdin);
int t = 1;
// cin >> t;
while(t--) solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |