# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
233382 | vioalbert | Garage (IOI09_garage) | C++14 | 7 ms | 384 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;
const int N = 105, M = 2005;
int n, m;
int cost[N], used[M], weight[M];
priority_queue<int, vector<int>, greater<int>> avail;
queue<int> q;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> cost[i];
avail.push(i);
}
for(int i = 1; i <= m; i++)
cin >> weight[i];
ll ans = 0;
for(int c = 0; c < 2*m; c++) {
int x; cin >> x;
if(x > 0) {
if(avail.empty())
q.push(x);
else
used[x] = avail.top(), avail.pop();
} else {
x *= -1;
ans += 1ll*cost[used[x]]*weight[x];
if(!q.empty())
used[q.front()] = used[x], q.pop();
else
avail.push(used[x]);
}
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |