結果

問題 No.1597 Matrix Sort
ユーザー 沙耶花沙耶花
提出日時 2021-07-09 21:46:44
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 370 ms / 1,500 ms
コード長 904 bytes
コンパイル時間 3,799 ms
使用メモリ 4,796 KB
最終ジャッジ日時 2023-02-01 22:53:47
合計ジャッジ時間 11,189 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,520 KB
testcase_01 AC 2 ms
3,524 KB
testcase_02 AC 1 ms
3,400 KB
testcase_03 AC 307 ms
4,724 KB
testcase_04 AC 324 ms
4,724 KB
testcase_05 AC 360 ms
4,660 KB
testcase_06 AC 351 ms
4,720 KB
testcase_07 AC 370 ms
4,792 KB
testcase_08 AC 269 ms
4,696 KB
testcase_09 AC 302 ms
4,668 KB
testcase_10 AC 195 ms
4,712 KB
testcase_11 AC 148 ms
4,696 KB
testcase_12 AC 139 ms
4,728 KB
testcase_13 AC 259 ms
4,656 KB
testcase_14 AC 300 ms
4,784 KB
testcase_15 AC 114 ms
4,716 KB
testcase_16 AC 173 ms
4,712 KB
testcase_17 AC 197 ms
4,688 KB
testcase_18 AC 321 ms
4,688 KB
testcase_19 AC 232 ms
4,784 KB
testcase_20 AC 188 ms
4,720 KB
testcase_21 AC 183 ms
4,740 KB
testcase_22 AC 187 ms
4,784 KB
testcase_23 AC 186 ms
4,796 KB
testcase_24 AC 45 ms
4,720 KB
testcase_25 AC 44 ms
4,660 KB
testcase_26 AC 1 ms
3,384 KB
testcase_27 AC 1 ms
3,416 KB
testcase_28 AC 2 ms
3,532 KB
testcase_29 AC 2 ms
3,424 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