Submission #309189

# Submission time Handle Problem Language Result Execution time Memory
309189 2020-10-02T20:46:25 Z BERNARB01 Garage (IOI09_garage) C++17
100 / 100
1 ms 384 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> r(n), w(m), e(2 * m);
  for (auto& x : r) {
    cin >> x;
  }
  for (auto& x : w) {
    cin >> x;
  }
  for (auto& x : e) {
    cin >> x;
  }
  set<int> s;
  for (int i = 0; i < n; i++) {
    s.insert(i);
  }
  queue<int> q;
  vector<int> taken(m);
  long long ans = 0;
  for (const auto& x : e) {
    int i = abs(x) - 1;
    if (x < 0) {
      s.insert(taken[i]);
    } else {
      if (!s.empty()) {
        ans += r[*s.begin()] * w[i];
        taken[i] = *s.begin();
        s.erase(s.begin());
      } else {
        q.push(i);
      }
    }
    while (!s.empty() && !q.empty()) {
      int j = q.front(); q.pop();
      ans += r[*s.begin()] * w[j];
      taken[j] = *s.begin();
      s.erase(s.begin());
    }
  }
  cout << ans << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct