結果

問題 No.1597 Matrix Sort
ユーザー nawawannawawan
提出日時 2021-07-09 22:09:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 351 ms / 1,500 ms
コード長 1,026 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 171,016 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-09-14 09:18:20
合計ジャッジ時間 8,084 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 298 ms
4,736 KB
testcase_04 AC 318 ms
4,572 KB
testcase_05 AC 336 ms
4,620 KB
testcase_06 AC 331 ms
4,704 KB
testcase_07 AC 351 ms
4,624 KB
testcase_08 AC 235 ms
4,720 KB
testcase_09 AC 270 ms
4,576 KB
testcase_10 AC 190 ms
4,576 KB
testcase_11 AC 143 ms
4,892 KB
testcase_12 AC 137 ms
4,684 KB
testcase_13 AC 256 ms
4,628 KB
testcase_14 AC 287 ms
4,580 KB
testcase_15 AC 114 ms
4,876 KB
testcase_16 AC 170 ms
4,660 KB
testcase_17 AC 194 ms
4,624 KB
testcase_18 AC 310 ms
4,628 KB
testcase_19 AC 229 ms
4,772 KB
testcase_20 AC 189 ms
4,616 KB
testcase_21 AC 181 ms
4,576 KB
testcase_22 AC 181 ms
4,580 KB
testcase_23 AC 179 ms
4,692 KB
testcase_24 AC 45 ms
4,620 KB
testcase_25 AC 44 ms
4,664 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    long long K;
    long long P;
    cin >> N >> K >> P;
    vector<long long> 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());
    int ub = P, lb = -1;
    while(ub - lb > 1){
        int mid = (ub + lb) / 2;
        long long cnt = 0;
        for(int i = 0; i < N; i++){
            if(mid < A[i]){
                int ind = upper_bound(B.begin(), B.end(), mid + P - A[i]) - lower_bound(B.begin(), B.end(), P - A[i]);
                cnt += ind;
            }
            else{
                int ind = upper_bound(B.begin(), B.end(), mid + P - A[i]) - lower_bound(B.begin(), B.end(), P - A[i]);
                int id = upper_bound(B.begin(), B.end(), mid - A[i]) - B.begin();
                cnt += ind;
                cnt += id;
            }
        }
        if(cnt >= K) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
}
0