結果

問題 No.1597 Matrix Sort
ユーザー ransewhaleransewhale
提出日時 2021-07-10 01:01:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 803 ms / 1,500 ms
コード長 1,009 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 80,820 KB
実行使用メモリ 5,144 KB
最終ジャッジ日時 2023-09-14 12:27:14
合計ジャッジ時間 14,232 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 746 ms
4,908 KB
testcase_04 AC 803 ms
5,144 KB
testcase_05 AC 785 ms
4,916 KB
testcase_06 AC 759 ms
4,936 KB
testcase_07 AC 752 ms
4,936 KB
testcase_08 AC 577 ms
4,888 KB
testcase_09 AC 597 ms
5,048 KB
testcase_10 AC 228 ms
4,904 KB
testcase_11 AC 227 ms
4,900 KB
testcase_12 AC 455 ms
4,940 KB
testcase_13 AC 636 ms
4,928 KB
testcase_14 AC 706 ms
4,932 KB
testcase_15 AC 176 ms
4,952 KB
testcase_16 AC 303 ms
4,896 KB
testcase_17 AC 346 ms
4,896 KB
testcase_18 AC 759 ms
4,876 KB
testcase_19 AC 754 ms
4,872 KB
testcase_20 AC 739 ms
5,048 KB
testcase_21 AC 497 ms
4,872 KB
testcase_22 AC 299 ms
4,952 KB
testcase_23 AC 261 ms
4,960 KB
testcase_24 AC 41 ms
4,936 KB
testcase_25 AC 39 ms
4,896 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
ll k,p,a[100100],b[100100];

bool check(ll x){
	int i;
	ll cnt=0ll;
	for(i=0; i<n; ++i){
		cnt += (ll)(std::lower_bound(b,b+n,x-a[i])-std::lower_bound(b,b+n,0ll-a[i]));
		cnt += (ll)(std::lower_bound(b,b+n,p+x-a[i])-std::lower_bound(b,b+n,p-a[i]));
	}
	return (cnt<k);
}

int main(void){
	int i;
	ll ok=0ll,ng,mid;
	std::cin >> n >> k >> p; ng = p;
	for(i=0; i<n; ++i){
		std::cin >> a[i];
	}
	for(i=0; i<n; ++i){
		std::cin >> b[i];
	}
	std::sort(b,b+n);
	while(ng-ok>1ll){
		mid = (ok+ng)/2;
		if(check(mid)){
			ok = mid;
		}else{
			ng = mid;
		}
	}
	std::cout << ok << std::endl;
	return 0;
}
0