結果

問題 No.1597 Matrix Sort
ユーザー 👑 NachiaNachia
提出日時 2021-07-09 21:52:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 321 ms / 1,500 ms
コード長 1,086 bytes
コンパイル時間 2,963 ms
コンパイル使用メモリ 154,428 KB
実行使用メモリ 4,884 KB
最終ジャッジ日時 2023-09-14 08:48:01
合計ジャッジ時間 8,811 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 294 ms
4,884 KB
testcase_04 AC 317 ms
4,732 KB
testcase_05 AC 321 ms
4,720 KB
testcase_06 AC 312 ms
4,720 KB
testcase_07 AC 306 ms
4,676 KB
testcase_08 AC 227 ms
4,704 KB
testcase_09 AC 229 ms
4,696 KB
testcase_10 AC 126 ms
4,708 KB
testcase_11 AC 89 ms
4,592 KB
testcase_12 AC 118 ms
4,608 KB
testcase_13 AC 245 ms
4,732 KB
testcase_14 AC 271 ms
4,656 KB
testcase_15 AC 79 ms
4,664 KB
testcase_16 AC 122 ms
4,732 KB
testcase_17 AC 141 ms
4,660 KB
testcase_18 AC 304 ms
4,656 KB
testcase_19 AC 192 ms
4,620 KB
testcase_20 AC 134 ms
4,668 KB
testcase_21 AC 124 ms
4,596 KB
testcase_22 AC 125 ms
4,700 KB
testcase_23 AC 110 ms
4,812 KB
testcase_24 AC 21 ms
4,620 KB
testcase_25 AC 18 ms
4,720 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ull MOD = 1000000007;
using mll = static_modint<1000000007>;
#define rep(i,n) for(int i=0; i<(n); i++)

ll N,K,P;
vector<ll> A,B;

ll cntB(ll bound){
  if(bound >= 0){
    return lower_bound(B.begin(),B.end(),bound) - B.begin();
  }
  return -(ll)(B.end() - lower_bound(B.begin(),B.end(),P+bound));
}

ll cnt(ll k){
  ll res = 0;
  for(ll a : A){
    ll l = 0, r = k + 1;
    l -= a; r -= a;
    res += cntB(r);
    res -= cntB(l);
  }
  return res;
}

int main(){
  cin >> N >> K >> P;
  A.resize(N); rep(i,N) cin >> A[i];
  B.resize(N); rep(i,N) cin >> B[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());

  ll l = 0, r = P;
  while(r-l > 1){
    ll m = (l+r) / 2;
    if(cnt(m-1) < K) l = m; else r = m;
  }
  cout << l << endl;
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0