結果
| 問題 | No.1597 Matrix Sort | 
| コンテスト | |
| ユーザー |  JiKuai | 
| 提出日時 | 2021-07-09 22:37:33 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 260 ms / 1,500 ms | 
| コード長 | 1,996 bytes | 
| コンパイル時間 | 2,357 ms | 
| コンパイル使用メモリ | 199,008 KB | 
| 最終ジャッジ日時 | 2025-01-22 22:19:09 | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
	cerr << "\e[1;33m" << s << " = [";
	while(l != r) {
		cerr << *l;
		cerr << (++l == r ? ']' : ',');
	}
	cerr << "\e[0m\n";
}
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*--------------------------------------------------------------------------------------*/
signed main() { EmiliaMyWife
	int n, p;
	ll k;
	cin >> n >> k >> p;
	vector<int> a(n), b(n);
	for(int &x : a)
		cin >> x;
	for(int &x : b)
		cin >> x;
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	int l = 0, r = p - 1;
	auto check = [&](int g) {
		ll res = 0;
		for(int x : a) {
			if(g >= x) {
				res += upper_bound(b.begin(), b.end(), g - x) - b.begin();
				res += b.end() - lower_bound(b.begin(), b.end(), p - x);
			}
			else {
				res += upper_bound(b.begin(), b.end(), p - (x - g)) - lower_bound(b.begin(), b.end(), p - x);
			}
		}
		//debug(g);
		//debug(res);
		return res;
	};
	while(l < r) {
		int m = l + r >> 1;
		if(check(m) < k)
			l = m + 1;
		else
			r = m;
	}
	cout << l << '\n';
}
            
            
            
        