結果

問題 No.1597 Matrix Sort
ユーザー umezoumezo
提出日時 2021-07-09 23:08:29
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 298 ms / 1,500 ms
コード長 700 bytes
コンパイル時間 1,900 ms
使用メモリ 6,712 KB
最終ジャッジ日時 2023-02-02 01:08:05
合計ジャッジ時間 7,688 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,476 KB
testcase_01 AC 1 ms
3,552 KB
testcase_02 AC 1 ms
3,404 KB
testcase_03 AC 284 ms
6,576 KB
testcase_04 AC 298 ms
6,588 KB
testcase_05 AC 287 ms
6,524 KB
testcase_06 AC 288 ms
6,680 KB
testcase_07 AC 285 ms
6,624 KB
testcase_08 AC 217 ms
6,520 KB
testcase_09 AC 223 ms
6,664 KB
testcase_10 AC 120 ms
6,572 KB
testcase_11 AC 128 ms
6,684 KB
testcase_12 AC 119 ms
6,576 KB
testcase_13 AC 229 ms
6,524 KB
testcase_14 AC 264 ms
6,652 KB
testcase_15 AC 80 ms
6,648 KB
testcase_16 AC 125 ms
6,576 KB
testcase_17 AC 144 ms
6,576 KB
testcase_18 AC 281 ms
6,592 KB
testcase_19 AC 187 ms
6,528 KB
testcase_20 AC 143 ms
6,528 KB
testcase_21 AC 134 ms
6,632 KB
testcase_22 AC 126 ms
6,528 KB
testcase_23 AC 122 ms
6,712 KB
testcase_24 AC 27 ms
6,664 KB
testcase_25 AC 24 ms
6,592 KB
testcase_26 AC 1 ms
3,500 KB
testcase_27 AC 1 ms
3,584 KB
testcase_28 AC 1 ms
3,596 KB
testcase_29 AC 2 ms
3,544 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