답안 #511155

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
511155 2022-01-15T09:31:16 Z 600Mihnea Garage (IOI09_garage) C++17
100 / 100
1 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 2000 + 7;
int n;
int m;
int rate[N];
int who[N];
int weight[N];
int sol;

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> rate[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> weight[i];
  }
  queue<int> q;
  for (int i = 1; i <= 2 * m; i++) {
    int j;
    cin >> j;
    if (j > 0) {
      q.push(j);
    } else {
      j *= -1;
      for (int k = 1; k <= n; k++) {
        if (who[k] == j) {
          who[k] = 0;
        }
      }
    }
    for (int k = 1; k <= n && !q.empty(); k++) {
      if (who[k] == 0) {
        sol += weight[q.front()] * rate[k];
        who[k] = q.front();
        q.pop();
      }
    }
  }

  cout << sol << "\n";

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 312 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 328 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