結果
問題 | No.1597 Matrix Sort |
ユーザー |
![]() |
提出日時 | 2021-07-09 23:08:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 391 ms / 1,500 ms |
コード長 | 700 bytes |
コンパイル時間 | 3,383 ms |
コンパイル使用メモリ | 194,120 KB |
最終ジャッジ日時 | 2025-01-22 22:33:32 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; ll n,k,p; ll A[100010],B[100100],C[200200]; bool f(ll x){ ll cnt=0; rep(i,n){ cnt+=upper_bound(C,C+2*n,p-A[i]+x)-lower_bound(C,C+2*n,p-A[i]); } if(cnt>=k) return true; else return false; } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); cin>>n>>k>>p; rep(i,n) cin>>A[i]; rep(i,n) cin>>B[i]; sort(A,A+n); sort(B,B+n); rep(i,n){ C[i]=B[i],C[i+n]=B[i]+p; } ll ng=-1,ok=p+1; while(ok-ng>1){ ll mid=(ng+ok)/2; if(f(mid)) ok=mid; else ng=mid; } cout<<ok<<endl; return 0; }