結果

問題 No.1597 Matrix Sort
ユーザー nakaken88nakaken88
提出日時 2021-07-09 23:05:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 1,500 ms
コード長 1,334 bytes
コンパイル時間 1,669 ms
コンパイル使用メモリ 171,160 KB
実行使用メモリ 4,720 KB
最終ジャッジ日時 2023-09-14 10:37:29
合計ジャッジ時間 6,750 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 224 ms
4,544 KB
testcase_04 AC 241 ms
4,568 KB
testcase_05 AC 243 ms
4,556 KB
testcase_06 AC 233 ms
4,600 KB
testcase_07 AC 233 ms
4,700 KB
testcase_08 AC 202 ms
4,640 KB
testcase_09 AC 190 ms
4,608 KB
testcase_10 AC 122 ms
4,572 KB
testcase_11 AC 89 ms
4,644 KB
testcase_12 AC 102 ms
4,556 KB
testcase_13 AC 187 ms
4,624 KB
testcase_14 AC 208 ms
4,556 KB
testcase_15 AC 72 ms
4,612 KB
testcase_16 AC 110 ms
4,640 KB
testcase_17 AC 126 ms
4,636 KB
testcase_18 AC 232 ms
4,612 KB
testcase_19 AC 163 ms
4,608 KB
testcase_20 AC 120 ms
4,648 KB
testcase_21 AC 112 ms
4,668 KB
testcase_22 AC 114 ms
4,600 KB
testcase_23 AC 103 ms
4,524 KB
testcase_24 AC 29 ms
4,656 KB
testcase_25 AC 25 ms
4,720 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include "debug.hpp"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

ll N, K, P;
vector<ll> A, B;
bool isOK(ll key) {
  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    ll a = A[i], temp = 0;
    if (a <= key) {
      ll not_temp = upper_bound(B.begin(), B.end(), P - a - 1) - B.begin();
      ll temp2 = upper_bound(B.begin(), B.end(), key - a) - B.begin();
      temp = N - (not_temp - temp2);
    } else {
      ll not_temp = upper_bound(B.begin(), B.end(), P - a - 1) - B.begin();
      temp = upper_bound(B.begin(), B.end(), key + P - a) - B.begin();
      debug(not_temp, temp);
      temp -= not_temp;
    }
    cnt += temp;
    debug(key, i, temp);
  }
  debug(key, cnt);
  return (cnt >= K);
}

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

  cin >> N >> K >> P;
  A.resize(N);
  B.resize(N);
  for (ll i = 0; i < N; i++) cin >> A[i];
  for (ll i = 0; i < N; i++) cin >> B[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  debug(A);

  // m 以下はK個以上ある?
  ll ok = P, ng = -1;
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;
    if (isOK(mid)) ok = mid;
    else ng = mid;
  }
  
  ll ans = ok;
  cout << ans << '\n';
  return 0;
}
0