結果

問題 No.1597 Matrix Sort
ユーザー seven_threeseven_three
提出日時 2021-07-09 23:17:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,176 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 98,448 KB
実行使用メモリ 5,644 KB
最終ジャッジ日時 2023-09-14 10:47:37
合計ジャッジ時間 8,014 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 AC 355 ms
5,332 KB
testcase_05 AC 356 ms
5,292 KB
testcase_06 AC 357 ms
5,464 KB
testcase_07 AC 365 ms
5,528 KB
testcase_08 AC 290 ms
5,328 KB
testcase_09 AC 292 ms
5,644 KB
testcase_10 AC 204 ms
5,416 KB
testcase_11 AC 168 ms
5,476 KB
testcase_12 AC 154 ms
5,416 KB
testcase_13 AC 280 ms
5,360 KB
testcase_14 AC 324 ms
5,420 KB
testcase_15 AC 124 ms
5,468 KB
testcase_16 AC 183 ms
5,364 KB
testcase_17 AC 210 ms
5,640 KB
testcase_18 AC 340 ms
5,324 KB
testcase_19 AC 246 ms
5,360 KB
testcase_20 AC 205 ms
5,508 KB
testcase_21 AC 199 ms
5,368 KB
testcase_22 AC 191 ms
5,640 KB
testcase_23 AC 185 ms
5,644 KB
testcase_24 AC 41 ms
5,332 KB
testcase_25 AC 39 ms
5,476 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long n, k, p;
vector<long long> a, b;
bool solve(long long x) {
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		long long l1 = x - a[i];
		auto itr = upper_bound(b.begin(), b.end(), l1);
		sum += int(itr - b.begin());
		long long l2 = p - a[i];
		long long r1 = p + x - a[i];
		auto itr1 = lower_bound(b.begin(), b.end(), l2);
		auto itr2 = upper_bound(b.begin(), b.end(), r1);
		sum += int(itr2 - itr1);
	}
	if (sum < k) {
		return true;
	}
	else {
		return false;
	}
}
int main() {
	cin >> n >> k >> p;
	long long a1, b1;
	for (int i = 0; i < n; i++) {
		cin >> a1;
		a.emplace_back(a1);
	}
	for (int i = 0; i < n; i++) {
		cin >> b1;
		b.emplace_back(b1);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	long long l = 0, r = p;
	while (r - l > 1) {
		long long mid = (l + r) / 2;
		if (solve(mid)) {
			l = mid;
		}
		else {
			r = mid;
		}
	}
	cout << r << endl;
}
0