結果

問題 No.1597 Matrix Sort
ユーザー w0mbatw0mbat
提出日時 2021-07-10 09:39:04
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 351 ms / 1,500 ms
コード長 740 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 86,608 KB
実行使用メモリ 172,640 KB
最終ジャッジ日時 2023-09-14 18:44:24
合計ジャッジ時間 7,977 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,156 KB
testcase_01 AC 73 ms
71,368 KB
testcase_02 AC 70 ms
71,080 KB
testcase_03 AC 351 ms
172,328 KB
testcase_04 AC 324 ms
172,228 KB
testcase_05 AC 288 ms
172,240 KB
testcase_06 AC 287 ms
171,848 KB
testcase_07 AC 281 ms
172,132 KB
testcase_08 AC 292 ms
172,220 KB
testcase_09 AC 256 ms
172,484 KB
testcase_10 AC 194 ms
169,884 KB
testcase_11 AC 206 ms
171,188 KB
testcase_12 AC 166 ms
100,088 KB
testcase_13 AC 183 ms
101,004 KB
testcase_14 AC 299 ms
172,328 KB
testcase_15 AC 156 ms
101,128 KB
testcase_16 AC 174 ms
101,236 KB
testcase_17 AC 235 ms
171,976 KB
testcase_18 AC 284 ms
172,236 KB
testcase_19 AC 255 ms
172,128 KB
testcase_20 AC 230 ms
172,304 KB
testcase_21 AC 228 ms
172,640 KB
testcase_22 AC 223 ms
171,816 KB
testcase_23 AC 209 ms
171,000 KB
testcase_24 AC 121 ms
101,608 KB
testcase_25 AC 112 ms
101,688 KB
testcase_26 AC 70 ms
71,088 KB
testcase_27 AC 69 ms
71,232 KB
testcase_28 AC 71 ms
71,380 KB
testcase_29 AC 134 ms
153,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
def main():
    input = sys.stdin.readline
    N, K, P = map(int, input().split())
    *A, = map(int, input().split())
    *B, = map(int, input().split())
    A.sort()
    B.sort()
    C = [0] * (P)
    for b in B:
        C[b] += 1
    for i in range(1, P):
        C[i] += C[i - 1]

    # x以下の要素の数
    def f(x):
        res = 0
        for a in A:
            # Ai+Bj <= x
            if x - a >= 0:
                res += C[x - a]
            # P <= Ai+Bi <= P+x
            res += C[min(P - 1, P + x - a)] - C[P - a - 1]
        return res

    l = -1
    r = P - 1
    while r - l > 1:
        m = (l + r) // 2
        if f(m) < K: l = m
        else: r = m
    print(r)

if __name__ == '__main__':
    main()
0