답안 #535007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
535007 2022-03-09T09:23:37 Z devariaota Garage (IOI09_garage) C++17
100 / 100
3 ms 332 KB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
typedef long long ll;
using namespace std;

ll n, m, ans;
ll car[2005], park[2005], rate[105];
queue<ll>q;
priority_queue<int, vector<int>, greater<int> >pq;

int main(){
  cin >> n >> m;
  for(int i = 1; i <= n; i++){
    ll rates; cin >> rates;
    pq.push(i);
    rate[i] = rates;
  }
  for(int i = 1; i <= m; i++){
    cin >> car[i];
  }
  for(int i = 1; i <= 2*m; i++){
    ll f; cin >> f;
    if(f > 0){
      if(!pq.empty()){
        ans += car[f]*rate[pq.top()];
        park[f] = pq.top();
        pq.pop();
      }
      else{
        q.push(f);
      }
    }
    else{
      f*=-1;
      pq.push(park[f]);
      if(!q.empty()){
        ll w = car[q.front()];
        ans += w*rate[pq.top()];
        park[q.front()] = pq.top();
        pq.pop();
        q.pop();
      }
    }
  }
  cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 292 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 296 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 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 300 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 332 KB Output is correct