結果

問題 No.1597 Matrix Sort
ユーザー hangin-svg
提出日時 2021-07-10 03:10:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 365 ms / 1,500 ms
コード長 835 bytes
コンパイル時間 1,833 ms
コンパイル使用メモリ 171,628 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-01 22:32:22
合計ジャッジ時間 8,807 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int n,p;

int count(vector<int> &a,int b,int l){
  auto left = lower_bound(a.begin(), a.end(),l-b);
  auto mid = lower_bound(a.begin(), a.end(),p-b);
  auto right = lower_bound(a.begin(), a.end(),l+p-b);

  return distance(a.begin(), left) + distance(mid, right);
}

int main(){

  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());

  ll ok = -1, ng = 2*p, check = (ok+ng)/2;
  while(ng-ok>1){
    check = (ok+ng)/2;
    ll accum = 0;
    for(int i=0; i<n; ++i) {
      accum += count(a,b[i],check);
    }
    if( accum < k ) ok=check;
    else ng = check;
  }

  cout << ok << endl;


}
0