結果
| 問題 | No.1597 Matrix Sort | 
| コンテスト | |
| ユーザー |  yamake | 
| 提出日時 | 2021-07-09 22:45:54 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 227 ms / 1,500 ms | 
| コード長 | 1,159 bytes | 
| コンパイル時間 | 1,791 ms | 
| コンパイル使用メモリ | 173,516 KB | 
| 実行使用メモリ | 7,296 KB | 
| 最終ジャッジ日時 | 2024-07-01 17:55:28 | 
| 合計ジャッジ時間 | 6,799 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define debug(output) if(debugFlag)cout<<#output<<"= "<<output<<endl
using lint = long long;
typedef pair<int,int> P;
const bool debugFlag=true;
const lint linf=1e18+7;
const lint inf=1e9+7;
const int MOD=1000000007;
signed main(){
  lint n,k,p;cin>>n>>k>>p;
  vector<lint> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  vector<lint> b(n);
  rep(i,n)cin>>b[i];
  sort(b.begin(),b.end());
  vector<lint> c(n*2);
  rep(i,n)c[i]=b[i]-p;
  rep(i,n)c[i+n]=b[i];
  vector<int> l(n),r(n);
  rep(i,n){
      auto it=lower_bound(c.begin(),c.end(),-a[i]);
      int ind=it-c.begin();
      l[i]=ind;r[i]=ind+n;
  }
  auto judge=[&](lint x){
      lint cnt=0;
      rep(i,n){
          auto it=lower_bound(c.begin()+l[i],c.end(),x-a[i]);
          int buf=it-c.begin();
          buf-=l[i];
          if(buf<0)buf=0;
          if(buf>n)buf=n;
          cnt+=buf;
      }
      return cnt<k;
  };
  lint d=0;lint u=p;
  while(u-d>1){
      lint mid=(u+d)/2;
      if(judge(mid))d=mid;
      else u=mid;
  }
  cout<<d<<"\n";
  return 0;
}
            
            
            
        