Submission #535013

# Submission time Handle Problem Language Result Execution time Memory
535013 2022-03-09T09:53:02 Z christinelynn Garage (IOI09_garage) C++17
100 / 100
3 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;
#pragma GCC optimize("Ofast")
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define endl '\n'
#define gl ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
  int n, m;
  cin >> n >> m;
  
  int r[n + 1], w[m + 1], p[m + 1];
  priority_queue<int, vector<int>, greater<int> > ada;
  queue<int> q;
  
  for(int i = 1; i <= n; i++) cin >> r[i];
  for(int i = 1; i <= m; i++) cin >> w[i];
  
  ll ans = 0;
  
  for(int i = 1; i <= n; i++) ada.push(i);
  for(int i = 1; i <= 2 * m; i++){
    int x;
    cin >> x;
    
    if(x > 0){
      if(ada.empty()) q.push(x);
      else{
        int pos = ada.top();
        ada.pop();
        
        ans += r[pos] * w[x];
        p[x] = pos;
      }
    }
    else{
      x *= -1;
      ada.push(p[x]);
      if(!q.empty()){
        int pake = q.front();
        int pos = ada.top();
        ada.pop();
        q.pop();
        
        ans += r[pos] * w[pake] * 1LL;
        p[pake] = pos;
      }
    }
  }
  
  cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 3 ms 204 KB Output is correct
17 Correct 2 ms 300 KB Output is correct
18 Correct 2 ms 304 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct