結果

問題 No.1597 Matrix Sort
ユーザー furafura
提出日時 2021-07-09 22:44:33
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 664 ms / 1,500 ms
コード長 634 bytes
コンパイル時間 1,815 ms
使用メモリ 5,160 KB
最終ジャッジ日時 2023-02-02 00:48:02
合計ジャッジ時間 12,584 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
4,900 KB
testcase_01 AC 1 ms
4,904 KB
testcase_02 AC 2 ms
4,904 KB
testcase_03 AC 614 ms
4,900 KB
testcase_04 AC 654 ms
5,156 KB
testcase_05 AC 664 ms
4,900 KB
testcase_06 AC 644 ms
4,900 KB
testcase_07 AC 664 ms
4,900 KB
testcase_08 AC 436 ms
5,156 KB
testcase_09 AC 449 ms
5,156 KB
testcase_10 AC 166 ms
4,904 KB
testcase_11 AC 125 ms
4,908 KB
testcase_12 AC 361 ms
5,156 KB
testcase_13 AC 509 ms
4,900 KB
testcase_14 AC 573 ms
5,160 KB
testcase_15 AC 114 ms
4,904 KB
testcase_16 AC 200 ms
5,152 KB
testcase_17 AC 223 ms
4,904 KB
testcase_18 AC 625 ms
4,908 KB
testcase_19 AC 621 ms
4,904 KB
testcase_20 AC 607 ms
5,156 KB
testcase_21 AC 297 ms
4,904 KB
testcase_22 AC 191 ms
4,904 KB
testcase_23 AC 175 ms
4,904 KB
testcase_24 AC 32 ms
4,904 KB
testcase_25 AC 29 ms
4,904 KB
testcase_26 AC 1 ms
4,900 KB
testcase_27 AC 2 ms
5,152 KB
testcase_28 AC 1 ms
4,900 KB
testcase_29 AC 2 ms
4,904 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