#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#include<bits/stdc++.h>
#define all(x) begin(x), end(x)
using namespace std;
const int maxn = 2e3 + 5, C = 1;
using ll = long long;
int n, m, b[maxn], r[maxn], w[maxn], dead[maxn], crap[maxn];
ll ans = 0;
queue<int> q;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) cin >> r[i];
for(int i = 1; i <= m; i++) cin >> w[i];
for(int t, i = 0; i < 2*m; i++) {
cin >> t;
if(t > 0) {
q.push(t);
} else {t*=-1;
dead[t] = 1;
if(crap[t]) b[crap[t]] = 0;
}
while(!q.empty() && dead[q.front()]) q.pop();
if(!q.empty()) {
int fp = 1;
while(b[fp]) fp++;
if(fp <= n) {
b[fp] = 1;
crap[q.front()] = fp;
ans += r[fp]*w[q.front()];
q.pop();
}
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |