# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535391 | devariaota | Garage (IOI09_garage) | C++17 | 2 ms | 348 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;
#define ll long long
int n, m;
int rate[105];
int weight[2005];
int loc[2005];
int main() {
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> rate[i];
}
for(int i = 1; i <= m; i++) {
cin >> weight[i];
}
priority_queue<int, vector<int>, greater<int> > pq;
for(int i = 1; i <= n; i++) {
pq.push(i);
}
int ans = 0;
queue<int> q;
for(int i = 1; i <= 2 * m; i++) {
int a;
cin >> a;
if (a > 0) {
if (!pq.empty()) {
loc[a] = pq.top();
ans += weight[a] * rate[loc[a]];
pq.pop();
}
else {
q.push(a);
}
}
else {
a *= -1;
if (!q.empty()) {
int next = q.front();
q.pop();
ans += weight[next] * rate[loc[a]];
}
else {
pq.push(loc[a]);
}
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |