Submission #936604

# Submission time Handle Problem Language Result Execution time Memory
936604 2024-03-02T10:28:31 Z Malix Garage (IOI09_garage) C++14
100 / 100
1 ms 360 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("test_input.txt", "r", stdin);
 //freopen("test_output.txt", "w", stdout);
  int n,m;cin>>n>>m;
  vi r(n);
  REP(i,0,n)cin>>r[i];
  vi w(m+1);
  REP(i,1,m+1)cin>>w[i];
  priority_queue<int, vector<int>, greater<int>> p;
  queue<int> q;
  REP(i,0,n)p.push(i);
  vi arr(m+1);
  int ans=0;int t;
  REP(i,0,2*m){
    cin>>t;
    if(t>0){
      if(p.empty()){
        q.push(t);
      }
      else{
        arr[t]=p.top();
        ans+=r[arr[t]]*w[t];
        p.pop();
      }
    }
    else{
      p.push(arr[-t]);
      if(!q.empty()){
        t=q.front();
        q.pop();
        arr[t]=p.top();
        ans+=r[arr[t]]*w[t];
        p.pop();
      }
    }
  }
  cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 360 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct