結果

問題 No.2422 regisys?
ユーザー siman
提出日時 2023-08-28 21:47:27
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,832 bytes
コンパイル時間 10,211 ms
コンパイル使用メモリ 144,508 KB
実行使用メモリ 10,632 KB
最終ジャッジ日時 2024-12-30 11:11:41
合計ジャッジ時間 14,221 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

struct Node {
  int i;
  int value;

  Node(int i = -1, int value = -1) {
    this->i = i;
    this->value = value;
  }

  bool operator>(const Node &n) const {
    return value > n.value;
  }
};

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }

  vector<int> C[2];
  for (int i = 0; i < M; ++i) {
    int t, c;
    cin >> t >> c;
    C[t].push_back(c);
  }

  sort(C[0].begin(), C[0].end());
  priority_queue <Node, vector<Node>, greater<Node>> pque_a;
  bool checked[N];
  memset(checked, false, sizeof(checked));
  int cnt = 0;

  for (int i = 0; i < N; ++i) {
    pque_a.push(Node(i, A[i]));
  }

  priority_queue <Node, vector<Node>, greater<Node>> stock;
  for (int c : C[0]) {
    while (not pque_a.empty() && pque_a.top().value <= c) {
      int i = pque_a.top().i;
      pque_a.pop();

      stock.push(Node(i, -B[i]));
    }

    if (not stock.empty()) {
      Node n = stock.top();
      stock.pop();
      checked[n.i] = true;
      cnt++;
    }
  }

  sort(C[1].begin(), C[1].end());
  reverse(C[1].begin(), C[1].end());
  priority_queue <Node, vector<Node>, greater<Node>> pque_b;
  for (int i = 0; i < N; ++i) {
    if (not checked[i]) {
      pque_b.push(Node(i, -B[i]));
    }
  }

  for (int c : C[1]) {
    while (not pque_b.empty()) {
      int i = pque_b.top().i;
      pque_b.pop();

      if (B[i] <= c) {
        checked[i] = true;
        cnt++;
        break;
      }
    }
  }

  cout << N - cnt << endl;

  return 0;
}
0