# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
601053 | SlyGaleeb | Garage (IOI09_garage) | C++17 | 2 ms | 360 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;
typedef long long ll;
#define ld long double
#define F first
#define S second
const ll N = 2e5 + 5;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m,ans=0;
cin >> n >> m;
vector<int>v(n+1),w(m+1);
priority_queue<int,vector<int>,greater<int>>pq;
queue<int>q;
map<int,int>mp;
for (int i = 1; i <= n; ++i) {
cin >> v[i];
pq.push(i);
}
for (int i = 1; i <= m; ++i)
cin >> w[i];
for (int i = 0; i < 2*m; ++i) {
while (!q.empty() && !pq.empty()) {
ans += w[q.front()]*v[pq.top()];
mp[q.front()] = pq.top();
q.pop();
pq.pop();
}
int a;
cin >> a;
if (a>0) {
if (pq.empty())
q.push(a);
else {
ans += w[a]*v[pq.top()];
mp[a] = pq.top();
pq.pop();
}
}
else {
pq.push(mp[-a]);
mp.erase(-a);
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |