結果

問題 No.1597 Matrix Sort
ユーザー yamakeyamake
提出日時 2021-07-09 22:46:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 1,500 ms
コード長 1,159 bytes
コンパイル時間 1,664 ms
コンパイル使用メモリ 172,044 KB
実行使用メモリ 7,264 KB
最終ジャッジ日時 2023-09-14 10:25:30
合計ジャッジ時間 6,704 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 161 ms
7,040 KB
testcase_04 AC 199 ms
6,972 KB
testcase_05 AC 226 ms
6,988 KB
testcase_06 AC 222 ms
7,092 KB
testcase_07 AC 229 ms
7,028 KB
testcase_08 AC 220 ms
6,960 KB
testcase_09 AC 222 ms
7,072 KB
testcase_10 AC 108 ms
6,952 KB
testcase_11 AC 116 ms
7,040 KB
testcase_12 AC 118 ms
7,040 KB
testcase_13 AC 201 ms
6,956 KB
testcase_14 AC 213 ms
7,228 KB
testcase_15 AC 84 ms
6,916 KB
testcase_16 AC 122 ms
7,032 KB
testcase_17 AC 138 ms
7,032 KB
testcase_18 AC 203 ms
7,264 KB
testcase_19 AC 161 ms
7,056 KB
testcase_20 AC 130 ms
7,104 KB
testcase_21 AC 124 ms
7,028 KB
testcase_22 AC 118 ms
7,040 KB
testcase_23 AC 112 ms
7,228 KB
testcase_24 AC 40 ms
7,092 KB
testcase_25 AC 37 ms
7,040 KB
testcase_26 AC 1 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,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0