| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1295978 | exoworldgd | Garage (IOI09_garage) | C++20 | 0 ms | 0 KiB |
#pragma GCC optimize("O5,unroll-loops,inline,fast-math")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
#define exoworldgd cin.tie(0)->sync_with_stdio(0),cout.tie(0)
#define int long long
using namespace std;
int n,m,r[105],w[2005],p[2005],x,s=0,c,yes;
bitset<105> t;
signed main(void) {
exoworldgd;
queue<int> q;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> r[i];
for (int i = 1; i <= m; i++) cin >> w[i];
for (int i = 0; i < 2*m; i++) {
cin >> x,yes=0;
if (x>0) {
for (int j = 0; j < n; j++) if (!t[j]) {t[j]=1, p[x]=j, s += r[j]*w[x], yes=1; break;}
if(!yes) q.push(x);
} else {
x = -x, t[p[x]]=0;
if (!q.empty()) c = q.front(), q.pop(), t[p[x]]=1, p[c]=p[x], s += r[p[c]]*w[c];
}
}
cout << s;
}
