# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440321 | dxz05 | Garage (IOI09_garage) | C++14 | 3 ms | 332 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.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2022;
int s[MAXN], w[MAXN];
int garage[MAXN];
int main(){
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> s[i];
for (int i = 1; i <= m; i++) cin >> w[i];
long long ans = 0;
queue<int> q;
for (int i = 1; i <= 2 * m; i++){
int x;
cin >> x;
if (x > 0){
q.push(x);
for (int i = 1; i <= n; i++){
if (garage[i] == 0){
garage[i] = x;
ans += w[x] * s[i];
q.pop();
break;
}
}
} else {
x = -x;
for (int i = 1; i <= n; i++){
if (garage[i] == x){
if (!q.empty()) {
garage[i] = q.front();
ans += w[q.front()] * s[i];
q.pop();
} else garage[i] = 0;
break;
}
}
}
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |