結果

問題 No.1597 Matrix Sort
ユーザー monnumonnu
提出日時 2021-07-09 22:28:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 407 ms / 1,500 ms
コード長 1,450 bytes
コンパイル時間 1,922 ms
コンパイル使用メモリ 170,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 09:43:34
合計ジャッジ時間 8,592 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 89 ms
4,376 KB
testcase_04 AC 379 ms
4,380 KB
testcase_05 AC 400 ms
4,380 KB
testcase_06 AC 404 ms
4,376 KB
testcase_07 AC 407 ms
4,376 KB
testcase_08 AC 282 ms
4,376 KB
testcase_09 AC 291 ms
4,376 KB
testcase_10 AC 196 ms
4,380 KB
testcase_11 AC 142 ms
4,380 KB
testcase_12 AC 156 ms
4,376 KB
testcase_13 AC 296 ms
4,376 KB
testcase_14 AC 353 ms
4,376 KB
testcase_15 AC 120 ms
4,380 KB
testcase_16 AC 179 ms
4,380 KB
testcase_17 AC 206 ms
4,376 KB
testcase_18 AC 365 ms
4,376 KB
testcase_19 AC 258 ms
4,376 KB
testcase_20 AC 201 ms
4,380 KB
testcase_21 AC 196 ms
4,376 KB
testcase_22 AC 190 ms
4,380 KB
testcase_23 AC 186 ms
4,380 KB
testcase_24 AC 46 ms
4,380 KB
testcase_25 AC 43 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
//#define INF 1000000000
#define INF 1000000000000000000

int main(){
  int N,P;
  ll K;
  cin>>N>>K>>P;
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<N;i++){
    cin>>B[i];
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());

  {
    int x=0;
    ll cnt=0;
    for(int i=0;i<N;i++){
      int k;
      k=upper_bound(B.begin(),B.end(),x-A[i])-B.begin();
      cnt+=(ll)k;
      //cout<<cnt<<" ";
      k=upper_bound(B.begin(),B.end(),x+P-A[i])-B.begin();
      cnt+=(ll)k;
      //cout<<k<<" ";
      //cout<<cnt<<" ";
      k=upper_bound(B.begin(),B.end(),P-1-A[i])-B.begin();
      cnt-=(ll)k;
      //cout<<P-1-A[i]<<endl;
      //cout<<cnt<<endl;
    }
    if(cnt>=K){
      cout<<0<<endl;
      return 0;
    }
  }

  int left=0;
  int right=P;
  while(left+1<right){
    int x=(left+right)/2;
    ll cnt=0;
    for(int i=0;i<N;i++){
      int k;
      if(A[i]+B[0]<=x){
        k=upper_bound(B.begin(),B.end(),x-A[i])-B.begin();
        cnt+=(ll)k;
      }
      k=upper_bound(B.begin(),B.end(),x+P-A[i])-B.begin();
      cnt+=(ll)k;
      k=upper_bound(B.begin(),B.end(),P-1-A[i])-B.begin();
      cnt-=(ll)k;
    }
    if(cnt>=K){
      right=x;
    }else{
      left=x;
    }
  }
  cout<<right<<endl;
}
0