結果

問題 No.1597 Matrix Sort
ユーザー yamakeyamake
提出日時 2021-07-09 22:45:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 1,500 ms
コード長 1,159 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 172,388 KB
実行使用メモリ 7,284 KB
最終ジャッジ日時 2023-09-14 10:23:04
合計ジャッジ時間 7,138 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 160 ms
7,124 KB
testcase_04 AC 198 ms
7,124 KB
testcase_05 AC 227 ms
7,124 KB
testcase_06 AC 222 ms
7,044 KB
testcase_07 AC 229 ms
6,928 KB
testcase_08 AC 221 ms
6,928 KB
testcase_09 AC 222 ms
7,068 KB
testcase_10 AC 107 ms
6,932 KB
testcase_11 AC 115 ms
7,040 KB
testcase_12 AC 117 ms
7,284 KB
testcase_13 AC 201 ms
7,040 KB
testcase_14 AC 214 ms
7,036 KB
testcase_15 AC 84 ms
6,928 KB
testcase_16 AC 123 ms
6,956 KB
testcase_17 AC 138 ms
7,132 KB
testcase_18 AC 202 ms
6,980 KB
testcase_19 AC 161 ms
6,936 KB
testcase_20 AC 131 ms
7,044 KB
testcase_21 AC 123 ms
6,988 KB
testcase_22 AC 119 ms
7,012 KB
testcase_23 AC 112 ms
7,004 KB
testcase_24 AC 41 ms
7,124 KB
testcase_25 AC 37 ms
6,960 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 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