結果

問題 No.1597 Matrix Sort
コンテスト
ユーザー aogera
提出日時 2025-12-28 17:33:19
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
結果
AC  
実行時間 885 ms / 1,500 ms
コード長 540 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,140 ms
コンパイル使用メモリ 348,524 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-28 17:33:39
合計ジャッジ時間 19,088 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/extc++.h>
using namespace std;
using ll=long long;

int main(){
	ll N,K,P;
	cin>>N>>K>>P;
	vector<ll> A(N),B(N);
	for(auto&a:A)cin>>a;
	for(auto&b:B)cin>>b;
	ranges::sort(B);

	auto get=[&](ll x){
		ll res=0;
		for(int i=0;i<N;i++){
			ll old=res;
			res+=ranges::upper_bound(B,x-A[i])-ranges::lower_bound(B,-A[i]);
			res+=ranges::upper_bound(B,P+x-A[i])-ranges::lower_bound(B,P-A[i]);
		}
		return res;
	};

	ll ok=-1,ng=P+1;
	while(ng-ok>1){
		ll md=(ok+ng)/2;
		if(get(md)>=K) ng=md;
		else ok=md;
	}
	cout<<ok+1<<endl;

}
0