#include <bits/stdc++.h>
using namespace std;
void testCase() {
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
vector<int> w(m + 1);
for (int i = 1; i <= m; ++i) {
cin >> w[i];
}
priority_queue<int, vector<int>, greater<int>> pq;
for (int i = 1; i <= n; ++i) {
pq.emplace(i);
}
queue<int> q;
vector<int> slot(n + 1);
vector<bool> del(m + 1);
int ans = 0;
for (int i = 1; i <= 2 * m; ++i) {
int x;
cin >> x;
if (x > 0) {
if (pq.empty()) {
q.emplace(x);
} else {
slot[x] = pq.top();
pq.pop();
ans += w[x] * a[slot[x]];
}
} else {
x = -x;
if (slot[x] == 0) {
del[x] = true;
} else {
pq.emplace(slot[x]);
while (!q.empty() && !pq.empty()) {
while (!q.empty() && del[q.front()]) {
q.pop();
}
if (!q.empty()) {
slot[q.front()] = pq.top();
pq.pop();
ans += w[q.front()] * a[slot[q.front()]];
q.pop();
}
}
}
}
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tests = 1;
for (int tc = 0; tc < tests; ++tc) {
testCase();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
13 |
Runtime error |
1 ms |
444 KB |
Execution killed with signal 6 |
14 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
17 |
Runtime error |
1 ms |
480 KB |
Execution killed with signal 6 |
18 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
19 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
20 |
Correct |
1 ms |
348 KB |
Output is correct |