結果

問題 No.1597 Matrix Sort
ユーザー umezoumezo
提出日時 2021-07-09 23:08:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 296 ms / 1,500 ms
コード長 700 bytes
コンパイル時間 1,994 ms
コンパイル使用メモリ 202,352 KB
実行使用メモリ 6,748 KB
最終ジャッジ日時 2023-09-14 10:41:10
合計ジャッジ時間 7,785 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 283 ms
6,496 KB
testcase_04 AC 296 ms
6,480 KB
testcase_05 AC 286 ms
6,472 KB
testcase_06 AC 286 ms
6,704 KB
testcase_07 AC 284 ms
6,504 KB
testcase_08 AC 216 ms
6,476 KB
testcase_09 AC 223 ms
6,504 KB
testcase_10 AC 122 ms
6,724 KB
testcase_11 AC 134 ms
6,480 KB
testcase_12 AC 118 ms
6,568 KB
testcase_13 AC 227 ms
6,556 KB
testcase_14 AC 260 ms
6,508 KB
testcase_15 AC 80 ms
6,528 KB
testcase_16 AC 121 ms
6,476 KB
testcase_17 AC 139 ms
6,496 KB
testcase_18 AC 280 ms
6,488 KB
testcase_19 AC 182 ms
6,500 KB
testcase_20 AC 141 ms
6,748 KB
testcase_21 AC 133 ms
6,656 KB
testcase_22 AC 123 ms
6,496 KB
testcase_23 AC 126 ms
6,508 KB
testcase_24 AC 28 ms
6,572 KB
testcase_25 AC 26 ms
6,496 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

ll n,k,p;
ll A[100010],B[100100],C[200200];

bool f(ll x){
  ll cnt=0;
  rep(i,n){
    cnt+=upper_bound(C,C+2*n,p-A[i]+x)-lower_bound(C,C+2*n,p-A[i]);
  }
  if(cnt>=k) return true;
  else return false;
}
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  cin>>n>>k>>p;
  rep(i,n) cin>>A[i];
  rep(i,n) cin>>B[i];
  sort(A,A+n);
  sort(B,B+n);
  rep(i,n){
    C[i]=B[i],C[i+n]=B[i]+p;
  }
  
  ll ng=-1,ok=p+1;
  while(ok-ng>1){
    ll mid=(ng+ok)/2;
    if(f(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
  
  return 0;
}
0