結果

問題 No.1597 Matrix Sort
ユーザー furafura
提出日時 2021-07-09 21:51:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 602 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 202,884 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-14 08:43:26
合計ジャッジ時間 13,000 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 659 ms
4,380 KB
testcase_08 AC 447 ms
4,376 KB
testcase_09 AC 461 ms
4,380 KB
testcase_10 AC 166 ms
4,380 KB
testcase_11 AC 124 ms
4,380 KB
testcase_12 AC 357 ms
4,380 KB
testcase_13 AC 502 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 116 ms
4,380 KB
testcase_16 AC 201 ms
4,376 KB
testcase_17 WA -
testcase_18 AC 619 ms
4,380 KB
testcase_19 AC 616 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 30 ms
4,376 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

using namespace std;

int main(){
	int n,k,p; scanf("%d%d%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){
		int 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