Submission #535806

# Submission time Handle Problem Language Result Execution time Memory
535806 2022-03-11T10:11:30 Z devariaota Garage (IOI09_garage) C++17
100 / 100
1 ms 452 KB
#include <bits/stdc++.h>
using namespace std;

#define nyahalo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define otsumiko exit(0);
#define mikodanye priority_queue<pair<long long, long long>, vector<pair<long long, long long> >, greater<pair<long long, long long> > >
#define mikochi priority_queue<long long, vector<long long>, greater<long long> >

int main() {
  nyahalo
  long long n, m, x, ans = 0;
  cin >> n >> m;
  long long r[n+1], w[m+1], a[m+1], b[n+1];
  queue<long long> qu;
  for (long long i=1; i<=n; i++) {
    cin >> r[i];
    b[i] = -1;
  }
  for (long long i=1; i<=m; i++) {
    cin >> w[i];
    a[i] = -1;
  }
  for (long long i=1; i<=2*m; i++) {
    cin >> x;
    if (x>0) {
      if (!qu.empty()) {
        qu.push(x);
      } else {
        for (long long j=1; j<=n; j++) {
          if (b[j] == -1) {
            b[j] = x;
            a[x] = j;
            ans += w[x]*r[j];
            break;
          }
        }
        if (a[x] == -1) {
          qu.push(x);
        }
      }
    } else {
      x = abs(x);
      b[a[x]] = -1;
      if (!qu.empty()) {
        ans += w[qu.front()]*r[a[x]];
        b[a[x]] = qu.front();
        a[qu.front()] = a[x];
        qu.pop();
      }
      a[x] = -1;
    }
  }
  cout << ans << "\n";
  otsumiko
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 288 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 452 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 368 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct