結果

問題 No.1597 Matrix Sort
ユーザー 629e^-b629e^-b
提出日時 2021-07-09 22:06:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 372 ms / 1,500 ms
コード長 1,285 bytes
コンパイル時間 4,319 ms
コンパイル使用メモリ 262,932 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 09:11:43
合計ジャッジ時間 11,874 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 338 ms
4,380 KB
testcase_04 AC 356 ms
4,380 KB
testcase_05 AC 369 ms
4,380 KB
testcase_06 AC 372 ms
4,380 KB
testcase_07 AC 372 ms
4,380 KB
testcase_08 AC 309 ms
4,380 KB
testcase_09 AC 314 ms
4,380 KB
testcase_10 AC 212 ms
4,376 KB
testcase_11 AC 164 ms
4,380 KB
testcase_12 AC 235 ms
4,376 KB
testcase_13 AC 317 ms
4,376 KB
testcase_14 AC 326 ms
4,376 KB
testcase_15 AC 201 ms
4,380 KB
testcase_16 AC 210 ms
4,380 KB
testcase_17 AC 213 ms
4,380 KB
testcase_18 AC 352 ms
4,376 KB
testcase_19 AC 244 ms
4,380 KB
testcase_20 AC 205 ms
4,380 KB
testcase_21 AC 197 ms
4,376 KB
testcase_22 AC 196 ms
4,376 KB
testcase_23 AC 198 ms
4,376 KB
testcase_24 AC 212 ms
4,380 KB
testcase_25 AC 212 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pdd = pair<ld, ld>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, P;
    ll K;
    cin >> N >> K >> P;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    for (int i = 0; i < N; ++i)
        cin >> B[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    // <= x: >= K
    auto isok = [&](ll x) -> bool {
        ll cnt = 0;
        for (int i = 0; i < N; ++i) {
            if (A[i] < P) {
                cnt += upper_bound(B.begin(), B.end(), x - A[i]) - B.begin();
            }
            cnt += max<int>(upper_bound(B.begin(), B.end(), x - A[i] + P) - lower_bound(B.begin(), B.end(), P - A[i]), 0);
        }
        return cnt >= K;
    };

    ll ok = 1e9, ng = -1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        (isok(mid) ? ok : ng) = mid;
    }

    cout << ok << endl;

    return 0;
}
0