#include <bits/stdc++.h>
using namespace std;
constexpr int NMAX = 105;
constexpr int MMAX = 2005;
int N, M;
int ans = 0;
int R[NMAX], W[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> M;
for (int i = 1; i <= N; ++ i )
cin >> R[i];
for (int i = 1; i <= M; ++ i )
cin >> W[i];
}
int occ[MMAX];
priority_queue <int, vector <int>, greater<int> > H;
queue <int> Q;
void Solve () {
int ans = 0;
for (int i = 1; i <= N; ++ i )
H.push(i);
for (int event = 1; event <= 2 * M; ++ event ) {
int x;
cin >> x;
if (x > 0)
Q.push(x);
else
H.push(occ[-x]);
while (!Q.empty() && !H.empty()) {
int car = Q.front();
Q.pop();
int park = H.top();
H.pop();
ans += W[car] * R[park];
occ[car] = park;
}
}
cout << ans << '\n';
}
int main () {
Read();
Solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Incorrect |
0 ms |
208 KB |
Output isn't correct |
11 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
12 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
13 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
14 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
15 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
16 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
17 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 11 |
18 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
19 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
20 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |