# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
733919 | vjudge1 | Garage (IOI09_garage) | C++17 | 2 ms | 212 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;
using ll = long long;
int main() {
int t, n, m, ans, i, z,j, x, r, p, s, y;
cin >> n >> m;
ll a[n + 2], b[m + 2], c[m + 2];
ans = 0;
priority_queue < ll , vector < ll > , greater< ll >> pq;
for ( i = 1; i <= n; i ++) {
cin >> a[i];
pq.push(i);
}
for ( i = 1; i <= m; i ++) {
cin >> b[i];
}
queue < ll > q;
for ( i = 1; i <= 2 * m; i ++) {
cin >> x;
if ( x < 0) {
r = -x;
pq.push(c[r]);
}
else {
if ( pq.empty()) {
q.push(x);
continue;
}
p = pq.top();
pq.pop();
c[x] = p;
ans += (a[p] * b[x]);
}
if ( !pq.empty() && !q.empty()) {
x = q.front();
q.pop();
p = pq.top();
pq.pop();
c[x] = p;
ans += (a[p] * b[x]);
}
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |