Submission #1078385

#TimeUsernameProblemLanguageResultExecution timeMemory
1078385sqrteipiGarage (IOI09_garage)C++14
100 / 100
2 ms348 KiB
#include <bits/stdc++.h> using namespace std; bool app[105]; int a[105], b[2005], c[2005]; int main() { int n, m, cnt=0; cin >> n >> m; for (int i=0; i<n; i++) cin >> a[i]; for (int i=0; i<m; i++) cin >> b[i]; queue<int> waiting; for (int i=0; i<2*m; i++) { int x; cin >> x; if (x > 0) { x -= 1; int p=0; while (p<n&&app[p]) p++; if (p==n) waiting.push(x); else app[p] = true, cnt += a[p] * b[x], c[x] = p; } else { x = -x - 1; app[c[x]] = false; if (!waiting.empty()) { int y = waiting.front(); app[c[x]] = true, cnt += a[c[x]] * b[y], c[y] = c[x]; waiting.pop(); } } } cout << cnt; }
#Verdict Execution timeMemoryGrader output
Fetching results...