結果
| 問題 | No.1597 Matrix Sort | 
| コンテスト | |
| ユーザー |  Nachia | 
| 提出日時 | 2021-07-09 21:52:49 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 394 ms / 1,500 ms | 
| コード長 | 1,086 bytes | 
| コンパイル時間 | 5,020 ms | 
| コンパイル使用メモリ | 154,596 KB | 
| 最終ジャッジ日時 | 2025-01-22 21:33:46 | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
#include <atcoder/all>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ull MOD = 1000000007;
using mll = static_modint<1000000007>;
#define rep(i,n) for(int i=0; i<(n); i++)
ll N,K,P;
vector<ll> A,B;
ll cntB(ll bound){
  if(bound >= 0){
    return lower_bound(B.begin(),B.end(),bound) - B.begin();
  }
  return -(ll)(B.end() - lower_bound(B.begin(),B.end(),P+bound));
}
ll cnt(ll k){
  ll res = 0;
  for(ll a : A){
    ll l = 0, r = k + 1;
    l -= a; r -= a;
    res += cntB(r);
    res -= cntB(l);
  }
  return res;
}
int main(){
  cin >> N >> K >> P;
  A.resize(N); rep(i,N) cin >> A[i];
  B.resize(N); rep(i,N) cin >> B[i];
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  ll l = 0, r = P;
  while(r-l > 1){
    ll m = (l+r) / 2;
    if(cnt(m-1) < K) l = m; else r = m;
  }
  cout << l << endl;
  return 0;
}
struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
            
            
            
        