結果

問題 No.1597 Matrix Sort
ユーザー furafura
提出日時 2021-07-09 22:44:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 685 ms / 1,500 ms
コード長 634 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 202,872 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 10:24:05
合計ジャッジ時間 13,005 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 640 ms
4,384 KB
testcase_04 AC 676 ms
4,376 KB
testcase_05 AC 682 ms
4,380 KB
testcase_06 AC 663 ms
4,376 KB
testcase_07 AC 685 ms
4,376 KB
testcase_08 AC 455 ms
4,380 KB
testcase_09 AC 469 ms
4,380 KB
testcase_10 AC 166 ms
4,376 KB
testcase_11 AC 123 ms
4,376 KB
testcase_12 AC 374 ms
4,376 KB
testcase_13 AC 526 ms
4,380 KB
testcase_14 AC 592 ms
4,380 KB
testcase_15 AC 120 ms
4,380 KB
testcase_16 AC 213 ms
4,380 KB
testcase_17 AC 237 ms
4,376 KB
testcase_18 AC 644 ms
4,376 KB
testcase_19 AC 642 ms
4,376 KB
testcase_20 AC 636 ms
4,380 KB
testcase_21 AC 422 ms
4,380 KB
testcase_22 AC 200 ms
4,376 KB
testcase_23 AC 175 ms
4,380 KB
testcase_24 AC 32 ms
4,376 KB
testcase_25 AC 30 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	int n,p;
	lint k; scanf("%d%lld%d",&n,&k,&p);
	vector<int> a(n),b(n);
	rep(i,n) scanf("%d",&a[i]);
	rep(j,n) scanf("%d",&b[j]);

	sort(b.begin(),b.end());

	auto f=[&](int tar){
		lint cnt=0;
		rep(i,n){
			cnt+=upper_bound(b.begin(),b.end(),tar-a[i])-b.begin();
			cnt+=upper_bound(b.begin(),b.end(),tar+p-a[i])-lower_bound(b.begin(),b.end(),p-a[i]);
		}
		return cnt;
	};

	int lo=-1,hi=p;
	while(hi-lo>1){
		int mi=(lo+hi)/2;
		if(f(mi)>=k) hi=mi;
		else         lo=mi;
	}
	printf("%d\n",hi);

	return 0;
}
0