Advertisement
erek1e

IOI '09 P5 - Garage

Jul 10th, 2023
1,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  9.     int n, m; cin >> n >> m;
  10.     vector<int> r(1+n), w(1+m);
  11.     for (int i = 1; i <= n; ++i) cin >> r[i];
  12.     for (int j = 1; j <= m; ++j) cin >> w[j];
  13.     queue<int> queue;
  14.     vector<int> car(1+n);
  15.     int freeSpaces = n, revenue = 0;
  16.     for (int t = 0; t < 2*m; ++t) {
  17.         int v; cin >> v;
  18.         int j = abs(v);
  19.         if (v > 0) queue.push(j);
  20.         else {
  21.             ++freeSpaces;
  22.             for (int i = 1; i <= n; ++i) {
  23.                 if (car[i] == j) {
  24.                     car[i] = 0;
  25.                     break;
  26.                 }
  27.             }
  28.         }
  29.         // clear queue
  30.         for (int i = 1; i <= n && freeSpaces && !queue.empty(); ++i) {
  31.             if (!car[i]) {
  32.                 --freeSpaces;
  33.                 car[i] = queue.front();
  34.                 queue.pop();
  35.                 revenue += r[i] * w[car[i]];
  36.             }
  37.         }
  38.     }
  39.     cout << revenue << endl;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement