# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100772 | Alexa2001 | Garage (IOI09_garage) | C++17 | 5 ms | 412 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 int Nmax = 1e4 + 5;
int n, m, x, i;
queue<int> q;
priority_queue< int, vector<int>, greater<int> > heap;
int coef[Nmax], w[Nmax], where[Nmax];
long long ans = 0;
int main()
{
// freopen("input", "r", stdin);
cin >> n >> m;
for(i=1; i<=n; ++i) cin >> coef[i];
for(i=1; i<=m; ++i) cin >> w[i];
for(i=1; i<=n; ++i) heap.push(i);
for(i=1; i<=2*m; ++i)
{
cin >> x;
if(x > 0) q.push(x);
else heap.push(where[-x]);
while(q.size() && heap.size())
{
x = q.front();
where[x] = heap.top();
ans += w[x] * coef[where[x]];
q.pop(); heap.pop();
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |