結果

問題 No.1597 Matrix Sort
ユーザー 沙耶花沙耶花
提出日時 2021-07-09 21:46:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 362 ms / 1,500 ms
コード長 904 bytes
コンパイル時間 6,708 ms
コンパイル使用メモリ 261,068 KB
実行使用メモリ 4,852 KB
最終ジャッジ日時 2023-09-14 08:25:10
合計ジャッジ時間 11,135 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 301 ms
4,520 KB
testcase_04 AC 318 ms
4,656 KB
testcase_05 AC 354 ms
4,644 KB
testcase_06 AC 345 ms
4,568 KB
testcase_07 AC 362 ms
4,572 KB
testcase_08 AC 258 ms
4,660 KB
testcase_09 AC 296 ms
4,632 KB
testcase_10 AC 200 ms
4,616 KB
testcase_11 AC 151 ms
4,612 KB
testcase_12 AC 139 ms
4,532 KB
testcase_13 AC 256 ms
4,664 KB
testcase_14 AC 296 ms
4,564 KB
testcase_15 AC 116 ms
4,696 KB
testcase_16 AC 173 ms
4,620 KB
testcase_17 AC 199 ms
4,632 KB
testcase_18 AC 315 ms
4,616 KB
testcase_19 AC 231 ms
4,612 KB
testcase_20 AC 188 ms
4,564 KB
testcase_21 AC 183 ms
4,660 KB
testcase_22 AC 186 ms
4,852 KB
testcase_23 AC 185 ms
4,676 KB
testcase_24 AC 46 ms
4,572 KB
testcase_25 AC 45 ms
4,524 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int main(){
	
	long long N,K,P;
	cin>>N>>K>>P;
	
	vector<long long> A(N),B(N);
	rep(i,N)cin>>A[i];
	rep(i,N)cin>>B[i];
	
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	
	long long ng = -1,ok = P;
	
	while(ok-ng>1){
		long long mid = (ok+ng)/2;
		
		long long cnt = 0LL;
		
		rep(i,N){
			if(A[i]<=mid){
				cnt += distance(B.begin(),upper_bound(B.begin(),B.end(),mid-A[i]));
				cnt += distance(lower_bound(B.begin(),B.end(),P-A[i]),upper_bound(B.begin(),B.end(),P-1));
			}
			else{
				cnt += distance(lower_bound(B.begin(),B.end(),P-A[i]),upper_bound(B.begin(),B.end(),P-(A[i]-mid)));
			}
		}
		
		
		if(cnt>=K)ok = mid;
		else ng = mid;
		
	}
	
	cout<<ok<<endl;
	
	
	return 0;
}
0