結果
問題 | No.1597 Matrix Sort |
ユーザー |
![]() |
提出日時 | 2021-07-09 23:40:16 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 405 ms / 1,500 ms |
コード長 | 1,177 bytes |
コンパイル時間 | 948 ms |
コンパイル使用メモリ | 98,796 KB |
実行使用メモリ | 5,708 KB |
最終ジャッジ日時 | 2024-07-01 18:31:13 |
合計ジャッジ時間 | 8,052 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#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; }