# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535806 | devariaota | Garage (IOI09_garage) | C++17 | 1 ms | 452 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 nyahalo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define otsumiko exit(0);
#define mikodanye priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > >
#define mikochi priority_queue<long long, vector<long long>, greater<long long> >
int main() {
nyahalo
long long n, m, x, ans = 0;
cin >> n >> m;
long long r[n+1], w[m+1], a[m+1], b[n+1];
queue<long long> qu;
for (long long i=1; i<=n; i++) {
cin >> r[i];
b[i] = -1;
}
for (long long i=1; i<=m; i++) {
cin >> w[i];
a[i] = -1;
}
for (long long i=1; i<=2*m; i++) {
cin >> x;
if (x>0) {
if (!qu.empty()) {
qu.push(x);
} else {
for (long long j=1; j<=n; j++) {
if (b[j] == -1) {
b[j] = x;
a[x] = j;
ans += w[x]*r[j];
break;
}
}
if (a[x] == -1) {
qu.push(x);
}
}
} else {
x = abs(x);
b[a[x]] = -1;
if (!qu.empty()) {
ans += w[qu.front()]*r[a[x]];
b[a[x]] = qu.front();
a[qu.front()] = a[x];
qu.pop();
}
a[x] = -1;
}
}
cout << ans << "\n";
otsumiko
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |