Submission #1079277

#TimeUsernameProblemLanguageResultExecution timeMemory
1079277vjudge1Garage (IOI09_garage)C++17
100 / 100
2 ms348 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; int main() { int n, m, money = 0; cin >> n >> m; vector<int> t(n); vector<int> w(m); vector<int> g(n, 0); queue<int> wait; for (int i = 0; i < n; i++) { cin >> t[i]; } for (int i = 0; i < m; i++) { cin >> w[i]; } for (int i = 0; i < m * 2; i++) { int temp; cin >> temp; if (temp > 0) { bool parked = false; for (int j = 0; j < n; j++) { if (g[j] == 0) { g[j] = temp; money += w[temp - 1] * t[j]; parked = true; break; } } if (!parked) wait.push(temp); } else { int car = -temp; for (int j = 0; j < n; j++) { if (g[j] == car) { g[j] = 0; if (!wait.empty()) { int nx = wait.front(); wait.pop(); g[j] = nx; money += w[nx - 1] * t[j]; } break; } } } } cout << money; }
#Verdict Execution timeMemoryGrader output
Fetching results...