# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
758186 | SanguineChameleon | Garage (IOI09_garage) | C++17 | 2 ms | 340 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;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxn = 1e2 + 20;
const int maxm = 2e3 + 20;
int rate[maxn];
int weight[maxm];
int cur_id[maxn];
void just_do_it() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> rate[i];
}
for (int i = 1; i <= m; i++) {
cin >> weight[i];
}
deque<int> q;
int res = 0;
for (int i = 1; i <= m * 2; i++) {
int id;
cin >> id;
if (id < 0) {
id = -id;
for (int j = 1; j <= n; j++) {
if (cur_id[j] == id) {
cur_id[j] = 0;
break;
}
}
}
else {
q.push_back(id);
}
while (!q.empty()) {
int id = q.front();
bool found = false;
for (int j = 1; j <= n; j++) {
if (cur_id[j] == 0) {
res += weight[id] * rate[j];
cur_id[j] = id;
found = true;
break;
}
}
if (found) {
q.pop_front();
}
else {
break;
}
}
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |