結果

問題 No.1597 Matrix Sort
ユーザー trineutrontrineutron
提出日時 2021-07-09 22:14:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 364 ms / 1,500 ms
コード長 782 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 204,128 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-09-14 09:27:37
合計ジャッジ時間 9,083 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 341 ms
4,736 KB
testcase_04 AC 353 ms
4,576 KB
testcase_05 AC 364 ms
4,760 KB
testcase_06 AC 356 ms
4,736 KB
testcase_07 AC 364 ms
4,624 KB
testcase_08 AC 274 ms
4,684 KB
testcase_09 AC 285 ms
4,676 KB
testcase_10 AC 197 ms
4,572 KB
testcase_11 AC 176 ms
4,700 KB
testcase_12 AC 166 ms
4,740 KB
testcase_13 AC 282 ms
4,576 KB
testcase_14 AC 317 ms
4,736 KB
testcase_15 AC 125 ms
4,620 KB
testcase_16 AC 186 ms
4,584 KB
testcase_17 AC 209 ms
4,568 KB
testcase_18 AC 346 ms
4,688 KB
testcase_19 AC 267 ms
4,620 KB
testcase_20 AC 202 ms
4,620 KB
testcase_21 AC 192 ms
4,632 KB
testcase_22 AC 197 ms
4,568 KB
testcase_23 AC 188 ms
4,572 KB
testcase_24 AC 40 ms
4,576 KB
testcase_25 AC 38 ms
4,888 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int64_t n, k, p;
    cin >> n >> k >> p;
    vector<int64_t> a(n), b(n);
    for (auto &&x : a)
    {
        cin >> x;
    }
    for (auto &&x : b)
    {
        cin >> x;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    auto f = [&](int64_t r)
    {
        int64_t res = 0;
        for (auto &&x : a)
        {
            res += lower_bound(b.begin(), b.end(), r - x) - b.begin();
        }
        return res;
    };

    int64_t l = 0, r = p;
    while (r - l > 1)
    {
        int64_t mid = (l + r) / 2;
        if (f(mid + p) - f(p) + f(mid) < k)
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }
    cout << l << endl;
    return 0;
}
0