Submission #156867

#TimeUsernameProblemLanguageResultExecution timeMemory
156867sochoGarage (IOI09_garage)C++14
100 / 100
5 ms380 KiB
#include "bits/stdc++.h" using namespace std; int main() { int n, m; cin >> n >> m; int occ[n]; memset(occ, 0, sizeof occ); int coe[n], where[m]; for (int i=0; i<n; i++) { cin >> coe[i]; } int wgt[m]; for (int i=0; i<m; i++) { cin >> wgt[i]; where[i] = -1; } int sm = 0; queue<int> wait; for (int i=0; i<2*m; i++) { int nxt; cin >> nxt; bool inc = true; if (nxt < 0) { inc = false; nxt = -nxt; } nxt--; if (inc) { wait.push(nxt); } else { int at = where[nxt]; occ[at] = false; } bool can = !wait.empty(); for (int j=0; j<n && can; j++) { if (!occ[j]) { occ[j] = true; int c = wait.front(); wait.pop(); sm += wgt[c] * coe[j]; where[c] = j; } can = !wait.empty(); } } cout << sm << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...