#include <bits/stdc++.h>
using namespace std;
const int mxn = 105;
const int mxm = 2005;
int n, m, x, r[mxn], w[mxm], pos[mxm], res = 0;
set<int> ok;
queue<int> q;
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> r[i], ok.insert(i);
for (int i = 1; i <= m; i++) cin >> w[i];
for (int i = 1; i <= m * 2; i++) {
cin >> x;
if (x > 0) {
if (ok.empty()) q.push(x);
else {
pos[x] = *ok.begin();
ok.erase(ok.begin());
}
} else {
x = -x;
ok.insert(pos[x]);
if (!q.empty()) {
pos[q.front()] = *ok.begin();
ok.erase(ok.begin());
q.pop();
}
}
}
for (int i = 1; i <= m; i++) res += r[pos[i]] * w[i];
cout << res << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
312 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
2 ms |
316 KB |
Output is correct |
20 |
Correct |
2 ms |
348 KB |
Output is correct |