답안 #534569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534569 2022-03-08T10:12:48 Z andecaandeci Garage (IOI09_garage) C++17
100 / 100
2 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
  cin.tie(0) -> ios_base::sync_with_stdio(0);

  int n, m;
  cin >> n >> m;
  vector<int> r(n + 1), w(m + 1);
  for(int i=1;i<=n;i++) cin >> r[i];
  for(int i=1;i<=m;i++) cin >> w[i];
  priority_queue<int, vector<int>, greater<int>> pq;
  for(int i=1;i<=n;i++) pq.push(i);
  queue<int> q;
  vector<int> loc(m + 1); // where car i is parked
  long long ans = 0;
  for(int i=1;i<=2*m;i++)
  {
    int x;
    cin >> x;
    if(x < 0)
    {
      pq.push(loc[-x]);
    }
    else
    {
      q.push(x);
    }
    while(!pq.empty() && !q.empty()){
      int cur = q.front(); q.pop();
      int p = pq.top(); pq.pop();
      loc[cur] = p;
      ans += (long long)r[p] * w[cur];
    }
  }
  cout << ans << '\n';
  
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 280 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct