Submission #511155

#TimeUsernameProblemLanguageResultExecution timeMemory
511155600MihneaGarage (IOI09_garage)C++17
100 / 100
1 ms332 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 2000 + 7;
int n;
int m;
int rate[N];
int who[N];
int weight[N];
int sol;

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> rate[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> weight[i];
  }
  queue<int> q;
  for (int i = 1; i <= 2 * m; i++) {
    int j;
    cin >> j;
    if (j > 0) {
      q.push(j);
    } else {
      j *= -1;
      for (int k = 1; k <= n; k++) {
        if (who[k] == j) {
          who[k] = 0;
        }
      }
    }
    for (int k = 1; k <= n && !q.empty(); k++) {
      if (who[k] == 0) {
        sol += weight[q.front()] * rate[k];
        who[k] = q.front();
        q.pop();
      }
    }
  }

  cout << sol << "\n";

  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...