結果

問題 No.1597 Matrix Sort
ユーザー monnumonnu
提出日時 2021-07-09 22:28:03
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 407 ms / 1,500 ms
コード長 1,450 bytes
コンパイル時間 1,421 ms
使用メモリ 6,952 KB
最終ジャッジ日時 2023-02-02 00:22:35
合計ジャッジ時間 8,361 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
4,900 KB
testcase_01 AC 1 ms
4,900 KB
testcase_02 AC 1 ms
4,904 KB
testcase_03 AC 86 ms
4,904 KB
testcase_04 AC 373 ms
4,900 KB
testcase_05 AC 396 ms
6,948 KB
testcase_06 AC 400 ms
4,900 KB
testcase_07 AC 407 ms
4,904 KB
testcase_08 AC 285 ms
4,904 KB
testcase_09 AC 293 ms
4,900 KB
testcase_10 AC 196 ms
6,952 KB
testcase_11 AC 140 ms
4,900 KB
testcase_12 AC 154 ms
6,952 KB
testcase_13 AC 295 ms
4,900 KB
testcase_14 AC 349 ms
6,948 KB
testcase_15 AC 119 ms
4,900 KB
testcase_16 AC 180 ms
4,900 KB
testcase_17 AC 205 ms
4,904 KB
testcase_18 AC 367 ms
4,904 KB
testcase_19 AC 254 ms
6,948 KB
testcase_20 AC 199 ms
4,904 KB
testcase_21 AC 195 ms
4,904 KB
testcase_22 AC 189 ms
4,904 KB
testcase_23 AC 186 ms
4,900 KB
testcase_24 AC 45 ms
4,900 KB
testcase_25 AC 43 ms
4,900 KB
testcase_26 AC 2 ms
4,900 KB
testcase_27 AC 1 ms
4,908 KB
testcase_28 AC 1 ms
6,948 KB
testcase_29 AC 1 ms
4,900 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