// [IOI2009] Garage
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M;
cin >> N >> M;
vector<int> R(N), W(M), P(N);
for (int &r : R) cin >> r; // 停车位s每千克收费的价格
for (int &w : W) cin >> w; // 车辆k的重量
set<int> F; // 空余的停车位
for (int i = 0; i < N; i++) F.insert(i);
queue<int> Q; // 入口队列
int ans = 0;
for (int i = 0, a; i < 2 * M and cin >> a; i++) {
if (a > 0) { // 到达
--a;
if (F.empty()) { // 没有空位
Q.push(a); // 排队
} else { // 有空位
assert(Q.empty());
int p = *F.begin();
ans += R[p] * W[a], F.erase(p), P[a] = p; // a停到p处
}
} else { // 离开
a = -a - 1, F.insert(P[a]), P[a] = -1;
if (!Q.empty()) {
int b = Q.front(), p = *F.begin();
ans += R[p] * W[b], Q.pop(), F.erase(p), P[b] = p;
}
}
}
cout << ans;
return 0;
}
// ❓❓ 0
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
5 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
6 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
7 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
8 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
9 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
10 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
11 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
12 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
13 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
14 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
15 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
16 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
18 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
19 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
20 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |