답안 #170468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170468 2019-12-25T11:29:41 Z AlexLuchianov Garage (IOI09_garage) C++14
100 / 100
5 ms 380 KB
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 2000;
int coef[1 + nmax], weight[1 + nmax];
int place[1 + nmax];

int main()
{
  int n, m;
  cin >> n >> m;
  for(int i = 1;i <= n; i++)
    cin >> coef[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);
  ll result = 0;
  queue<int> q;

  for(int i = 1;i <= 2 * m; i++){
    int op;
    cin >> op;
    if(op < 0){
      op = -op;
      pq.push(place[op]);
    } else
      q.push(op);
    while(0 < q.size() && 0 < pq.size()){
      int car = q.front();
      q.pop();
      int target = pq.top();
      pq.pop();
      place[car] = target;
      result += weight[car] * coef[target];
    }
  }
  cout << result;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 296 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 380 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 4 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct