# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
156867 | socho | Garage (IOI09_garage) | C++14 | 5 ms | 380 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;
int main() {
int n, m;
cin >> n >> m;
int occ[n];
memset(occ, 0, sizeof occ);
int coe[n], where[m];
for (int i=0; i<n; i++) {
cin >> coe[i];
}
int wgt[m];
for (int i=0; i<m; i++) {
cin >> wgt[i];
where[i] = -1;
}
int sm = 0;
queue<int> wait;
for (int i=0; i<2*m; i++) {
int nxt;
cin >> nxt;
bool inc = true;
if (nxt < 0) {
inc = false;
nxt = -nxt;
}
nxt--;
if (inc) {
wait.push(nxt);
}
else {
int at = where[nxt];
occ[at] = false;
}
bool can = !wait.empty();
for (int j=0; j<n && can; j++) {
if (!occ[j]) {
occ[j] = true;
int c = wait.front(); wait.pop();
sm += wgt[c] * coe[j];
where[c] = j;
}
can = !wait.empty();
}
}
cout << sm << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |