# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
366900 | kostia244 | Garage (IOI09_garage) | C++17 | 1 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |