結果

問題 No.1597 Matrix Sort
ユーザー seven_threeseven_three
提出日時 2021-07-09 23:40:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 370 ms / 1,500 ms
コード長 1,177 bytes
コンパイル時間 1,001 ms
コンパイル使用メモリ 97,828 KB
実行使用メモリ 5,684 KB
最終ジャッジ日時 2023-09-14 11:00:03
合計ジャッジ時間 8,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 344 ms
5,660 KB
testcase_04 AC 361 ms
5,684 KB
testcase_05 AC 370 ms
5,392 KB
testcase_06 AC 360 ms
5,324 KB
testcase_07 AC 370 ms
5,328 KB
testcase_08 AC 283 ms
5,420 KB
testcase_09 AC 294 ms
5,408 KB
testcase_10 AC 201 ms
5,272 KB
testcase_11 AC 170 ms
5,468 KB
testcase_12 AC 155 ms
5,516 KB
testcase_13 AC 282 ms
5,332 KB
testcase_14 AC 321 ms
5,336 KB
testcase_15 AC 128 ms
5,452 KB
testcase_16 AC 185 ms
5,664 KB
testcase_17 AC 212 ms
5,500 KB
testcase_18 AC 343 ms
5,500 KB
testcase_19 AC 248 ms
5,328 KB
testcase_20 AC 204 ms
5,384 KB
testcase_21 AC 195 ms
5,388 KB
testcase_22 AC 198 ms
5,332 KB
testcase_23 AC 184 ms
5,328 KB
testcase_24 AC 48 ms
5,388 KB
testcase_25 AC 46 ms
5,276 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 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 = -1, r = p;
	while (r - l > 1) {
		long long mid = (l + r) / 2;
		if (solve(mid)) {
			l = mid;
		}
		else {
			r = mid;
		}
	}
	cout << r << endl;
}
0