Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- int n, m; cin >> n >> m;
- vector<int> r(1+n), w(1+m);
- for (int i = 1; i <= n; ++i) cin >> r[i];
- for (int j = 1; j <= m; ++j) cin >> w[j];
- queue<int> queue;
- vector<int> car(1+n);
- int freeSpaces = n, revenue = 0;
- for (int t = 0; t < 2*m; ++t) {
- int v; cin >> v;
- int j = abs(v);
- if (v > 0) queue.push(j);
- else {
- ++freeSpaces;
- for (int i = 1; i <= n; ++i) {
- if (car[i] == j) {
- car[i] = 0;
- break;
- }
- }
- }
- // clear queue
- for (int i = 1; i <= n && freeSpaces && !queue.empty(); ++i) {
- if (!car[i]) {
- --freeSpaces;
- car[i] = queue.front();
- queue.pop();
- revenue += r[i] * w[car[i]];
- }
- }
- }
- cout << revenue << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement