結果

問題 No.1597 Matrix Sort
ユーザー JiKuaiJiKuai
提出日時 2021-07-09 22:37:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 270 ms / 1,500 ms
コード長 1,996 bytes
コンパイル時間 2,179 ms
コンパイル使用メモリ 203,008 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 09:57:13
合計ジャッジ時間 7,594 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 270 ms
4,376 KB
testcase_04 AC 261 ms
4,380 KB
testcase_05 AC 266 ms
4,380 KB
testcase_06 AC 266 ms
4,380 KB
testcase_07 AC 264 ms
4,380 KB
testcase_08 AC 215 ms
4,380 KB
testcase_09 AC 212 ms
4,376 KB
testcase_10 AC 121 ms
4,380 KB
testcase_11 AC 87 ms
4,376 KB
testcase_12 AC 102 ms
4,376 KB
testcase_13 AC 209 ms
4,380 KB
testcase_14 AC 234 ms
4,376 KB
testcase_15 AC 75 ms
4,376 KB
testcase_16 AC 109 ms
4,380 KB
testcase_17 AC 132 ms
4,380 KB
testcase_18 AC 268 ms
4,380 KB
testcase_19 AC 172 ms
4,376 KB
testcase_20 AC 128 ms
4,380 KB
testcase_21 AC 116 ms
4,376 KB
testcase_22 AC 115 ms
4,380 KB
testcase_23 AC 118 ms
4,376 KB
testcase_24 AC 23 ms
4,380 KB
testcase_25 AC 19 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     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';
}
0