結果

問題 No.1597 Matrix Sort
ユーザー shobonvipshobonvip
提出日時 2023-11-15 02:44:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 809 ms / 1,500 ms
コード長 2,288 bytes
コンパイル時間 4,363 ms
コンパイル使用メモリ 265,980 KB
実行使用メモリ 12,724 KB
最終ジャッジ日時 2023-11-15 02:44:29
合計ジャッジ時間 19,070 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,444 KB
testcase_01 AC 4 ms
11,444 KB
testcase_02 AC 4 ms
11,444 KB
testcase_03 AC 765 ms
12,724 KB
testcase_04 AC 809 ms
12,724 KB
testcase_05 AC 805 ms
12,724 KB
testcase_06 AC 771 ms
12,724 KB
testcase_07 AC 796 ms
12,724 KB
testcase_08 AC 539 ms
12,724 KB
testcase_09 AC 598 ms
12,724 KB
testcase_10 AC 238 ms
12,724 KB
testcase_11 AC 200 ms
12,724 KB
testcase_12 AC 442 ms
12,724 KB
testcase_13 AC 625 ms
12,724 KB
testcase_14 AC 693 ms
12,724 KB
testcase_15 AC 171 ms
12,724 KB
testcase_16 AC 281 ms
12,724 KB
testcase_17 AC 327 ms
12,724 KB
testcase_18 AC 749 ms
12,724 KB
testcase_19 AC 788 ms
12,724 KB
testcase_20 AC 742 ms
12,724 KB
testcase_21 AC 546 ms
12,724 KB
testcase_22 AC 283 ms
12,724 KB
testcase_23 AC 246 ms
12,724 KB
testcase_24 AC 45 ms
12,724 KB
testcase_25 AC 42 ms
12,724 KB
testcase_26 AC 4 ms
11,444 KB
testcase_27 AC 4 ms
11,444 KB
testcase_28 AC 4 ms
11,444 KB
testcase_29 AC 5 ms
11,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint1000000007 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

//defmodfact
const int COMinitMAX = 998244;
mint fact[COMinitMAX+1], factinv[COMinitMAX+1];

void modfact(){
	fact[0] = 1;
	for (int i=1; i<=COMinitMAX; i++){
		fact[i] = fact[i-1] * i;
	}
	factinv[COMinitMAX] = fact[COMinitMAX].inv();
	for (int i=COMinitMAX-1; i>=0; i--){
		factinv[i] = factinv[i+1] * (i+1);
	}
}

mint cmb(int a, int b){
	if (a<b || b<0) return mint(0);
	return fact[a]*factinv[b]*factinv[a-b];
}
//--------

// importbisect
template <typename T>
int bisect_left(vector<T> &X, T v){
	return lower_bound(X.begin(), X.end(), v) - X.begin();
}

template <typename T>
int bisect_right(vector<T> &X, T v){
	return upper_bound(X.begin(), X.end(), v) - X.begin();
}
// -----


int main(){
	int n; cin >> n;
	ll k; cin >> k;
	int p; cin >> p;
	vector<ll> a(n), b(n);
	rep(i,0,n){
		cin >> a[i];
	}
	rep(i,0,n){
		cin >> b[i];
	}
	sort(b.begin(), b.end());

	auto get = [&](ll y, ll l, ll r){
		return bisect_left(b, -y+r) - bisect_left(b, -y+l);
	};

	auto check = [&](ll x){
		ll tmp = 0;
		rep(i,0,n){
			tmp += get(a[i], 0, x);
			tmp += get(a[i], p, p+x);
		}
		return tmp < k;
	};
	
	ll ub = p;
	ll lb = 0;
	while (ub - lb > 1){
		ll targ = (ub + lb) / 2;
		if (check(targ)) lb = targ;
		else ub = targ;
	}

	cout << lb << '\n';
}

0