結果
| 問題 |
No.1597 Matrix Sort
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-09 23:05:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 325 ms / 1,500 ms |
| コード長 | 1,334 bytes |
| コンパイル時間 | 1,679 ms |
| コンパイル使用メモリ | 172,616 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-01 18:09:37 |
| 合計ジャッジ時間 | 7,182 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef LOCAL
#include "debug.hpp"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
ll N, K, P;
vector<ll> A, B;
bool isOK(ll key) {
ll cnt = 0;
for (ll i = 0; i < N; i++) {
ll a = A[i], temp = 0;
if (a <= key) {
ll not_temp = upper_bound(B.begin(), B.end(), P - a - 1) - B.begin();
ll temp2 = upper_bound(B.begin(), B.end(), key - a) - B.begin();
temp = N - (not_temp - temp2);
} else {
ll not_temp = upper_bound(B.begin(), B.end(), P - a - 1) - B.begin();
temp = upper_bound(B.begin(), B.end(), key + P - a) - B.begin();
debug(not_temp, temp);
temp -= not_temp;
}
cnt += temp;
debug(key, i, temp);
}
debug(key, cnt);
return (cnt >= K);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> K >> P;
A.resize(N);
B.resize(N);
for (ll i = 0; i < N; i++) cin >> A[i];
for (ll i = 0; i < N; i++) cin >> B[i];
sort(A.begin(), A.end());
sort(B.begin(), B.end());
debug(A);
// m 以下はK個以上ある?
ll ok = P, ng = -1;
while (abs(ok - ng) > 1) {
ll mid = (ok + ng) / 2;
if (isOK(mid)) ok = mid;
else ng = mid;
}
ll ans = ok;
cout << ans << '\n';
return 0;
}