Submission #300249

#TimeUsernameProblemLanguageResultExecution timeMemory
300249fpc_coderGarage (IOI09_garage)C++17
100 / 100
4 ms512 KiB
#include <bits/stdc++.h> using namespace std; const int N = 105; const int M = 2005; int w[M], r[N], pos[M]; int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> r[i]; for (int i = 1; i <= m; i++) cin >> w[i]; queue<int> wait; vector<int> empty_pos(n); for (int i = 0; i < n; i++) empty_pos[i] = i + 1; int ans = 0; for (int i = 0; i < 2 * m; i++) { int car; cin >> car; if (car > 0) { if (!empty_pos.empty()) { vector<int>::iterator mn_it = min_element(empty_pos.begin(), empty_pos.end()); int mn_pos = *mn_it; ans += w[car] * r[mn_pos]; pos[car] = mn_pos; empty_pos.erase(mn_it); } else wait.push(car); } else { car = -car; if (!wait.empty()) { int waiting = wait.front(); wait.pop(); pos[waiting] = pos[car]; ans += w[waiting] * r[pos[waiting]]; } else empty_pos.push_back(pos[car]); } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...