# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74655 | arman_ferdous | Garage (IOI09_garage) | C++17 | 4 ms | 888 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;
typedef long long ll;
int n, m, r[110], w[2010], arr[110];
int main() {
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++)
scanf("%d", &r[i]);
for(int i = 1; i <= m; i++)
scanf("%d", &w[i]);
ll ans = 0;
int Q = m + m;
queue<int> q;
while(Q--) {
int id; scanf("%d", &id);
if(id < 0) {
id = -id;
for(int i = 1; i <= n; i++) if(arr[i] == id) {
arr[i] = 0;
if(!q.empty()) {
arr[i] = q.front();
ans += 1ll * w[arr[i]] * r[i];
q.pop();
} break;
}
}
else {
for(int i = 1; i <= n; i++) if(arr[i] == 0) {
arr[i] = id; id = 0;
ans += 1ll * w[arr[i]] * r[i]; break;
}
if(id) q.push(id);
}
} printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |