# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
79870 | shoemakerjo | Garage (IOI09_garage) | C++14 | 3 ms | 1088 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 pii pair<int, int>
int N, M;
int rate[105];
int weight[10010];
int myspot[10010];
set<pii> curout;
set<int> openspots;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N >> M;
for (int i = 1; i <= N; i++) {
cin >> rate[i];
openspots.insert(i);
}
for (int i = 1; i <= M; i++) {
cin >> weight[i];
}
int ct = 0;
int ans = 0;
int cur;
for (int i = 0; i < 2*M; i++) {
cin >> cur;
if (cur < 0) {
cur *= -1;
// openspots.insert(myspot[cur]);
if (curout.size()) {
pii val = *curout.begin();
curout.erase(curout.begin());
ans += weight[val.second] * rate[myspot[cur]];
myspot[val.second] = myspot[cur];
}
else openspots.insert(myspot[cur]);
}
else {
if (openspots.size()) {
ans += weight[cur] * (rate[*openspots.begin()]);
myspot[cur] = *openspots.begin();
openspots.erase(openspots.begin());
}
else curout.insert(pii(++ct, cur));
}
}
// for (int i = 1; i <= M; i++) {
// cout << i << " went to spot " << myspot[i] << endl;
// }
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |