Submission #767890

#TimeUsernameProblemLanguageResultExecution timeMemory
767890benjaminkleynGarage (IOI09_garage)C++17
100 / 100
2 ms344 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m, r[100], w[2000]; int pos[2000]; bool open[100]; int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> r[i]; open[i] = true; } for (int i = 0; i < m; i++) { cin >> w[i]; pos[i] = -1; } ll ans = 0; queue<int> q; for (int t = 0, x; t < 2 * m; t++) { cin >> x; if (x < 0) open[pos[-x-1]] = true; else q.push(x-1); for (int i = 0, j; i < 100 && !q.empty(); i++) if (open[i]) { j = q.front(); q.pop(); // cout << "car " << j + 1 << " parks in space " << i + 1 << ".\n"; open[i] = false, pos[j] = i; ans += w[j] * r[i]; } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...