# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
943322 | maxFedorchuk | Garage (IOI09_garage) | C++17 | 2 ms | 4696 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;
const long long MX=2e5+10;
long long msq[MX],w[MX],cs[MX],ans=0;
int main()
{
cin.tie(0);
ios_base::sync_with_stdio(0);
priority_queue < pair < long long , long long > , vector < pair < long long , long long > > , greater < pair < long long , long long > > > qp;
long long n,m;
cin>>n>>m;
for(long long i=1;i<=n;i++)
{
cin>>cs[i];
qp.push({cs[i],i});
}
for(long long i=1;i<=m;i++)
{
cin>>w[i];
}
queue < long long > qm;
for(long long i=1;i<=2*m;i++)
{
long long a;
cin>>a;
if(a>0)
{
qm.push(a);
}
else
{
a=(-a);
qp.push({cs[msq[a]],msq[a]});
msq[a]=0;
}
if(!qp.empty() && !qm.empty())
{
int o1=qp.top().second;
qp.pop();
int o2=qm.front();
qm.pop();
ans+=w[o2]*cs[o1];
msq[o2]=o1;
}
}
cout<<ans<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |