제출 #535391

#제출 시각아이디문제언어결과실행 시간메모리
535391devariaotaGarage (IOI09_garage)C++17
40 / 100
2 ms348 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int n, m;
int rate[105];
int weight[2005];
int loc[2005];

int main() {
  cin >> n >> m;
  for(int i = 1; i <= n; i++) {
    cin >> rate[i];
  }
  for(int i = 1; i <= m; i++) {
    cin >> weight[i];
  }
  priority_queue<int, vector<int>, greater<int> > pq;
  for(int i = 1; i <= n; i++) {
    pq.push(i);
  }
  int ans = 0;
  queue<int> q;
  
  for(int i = 1; i <= 2 * m; i++) {
    int a;
    cin >> a;
    if (a > 0) {
      if (!pq.empty()) {
        loc[a] = pq.top();
        ans += weight[a] * rate[loc[a]];
        pq.pop();
      }
      else {
        q.push(a);
      }
    }
    else {
      a *= -1;
      if (!q.empty()) {
        int next = q.front();
        q.pop();
        ans += weight[next] * rate[loc[a]];
      }
      else {
        pq.push(loc[a]);
      }
    }
  }
  cout << ans << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...