# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
423284 | haxorman | Garage (IOI09_garage) | C++14 | 3 ms | 332 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 mxN = 107;
const int mxM = 2007;
bool arr[mxN];
int r[mxN], w[mxM], pos[mxM];
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> r[i];
}
for (int i = 1; i <= m; ++i) {
cin >> w[i];
}
long long ans = 0;
queue<int> q;
for (int iter = 1; iter <= 2 * m; ++iter) {
int car;
cin >> car;
if (car < 0) {
car = -car;
arr[pos[car]] = false;
for (int i = 1; i <= n && q.size(); ++i) {
if (!arr[i]) {
cout << q.front() << ' ' << i << "\n";
arr[i] = true;
ans += r[i] * w[q.front()];
pos[q.front()] = i;
q.pop();
}
}
}
else {
q.push(car);
for (int i = 1; i <= n && q.size(); ++i) {
if (!arr[i]) {
//cout << q.front() << ' ' << i << "\n";
arr[i] = true;
ans += r[i] * w[q.front()];
pos[q.front()] = i;
q.pop();
}
}
}
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |