#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, m; cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
priority_queue<int> pq;
for (int i = 0; i < n; ++i) {
pq.push(-i);
}
vector<int> vis(n), pos(n);
queue<int> q;
int res = 0;
for (int i = 0; i < 2 * m; ++i) {
int x; cin >> x;
if (x > 0) {
q.push(x - 1);
} else {
int p = pos[-1 - x];
vis[p] ^= 1;
pq.push(-p);
}
while (q.size()) {
while (pq.size() && vis[-pq.top()]) {
pq.pop();
}
if (!pq.size()) {
break;
}
int u = q.front(); q.pop();
int j = -pq.top(); pq.pop();
res += a[j] * b[u];
pos[u] = j;
vis[j] ^= 1;
}
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
2 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
5 |
Runtime error |
2 ms |
420 KB |
Execution killed with signal 6 |
6 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
10 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
11 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
12 |
Runtime error |
1 ms |
856 KB |
Execution killed with signal 6 |
13 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
14 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
15 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
16 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 6 |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
18 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
19 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
20 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |