結果

問題 No.1597 Matrix Sort
ユーザー H3PO4
提出日時 2023-03-30 09:26:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 389 ms / 1,500 ms
コード長 612 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 173,476 KB
最終ジャッジ日時 2024-09-21 21:01:16
合計ジャッジ時間 8,758 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K, P = map(int, input().split())
A = tuple(int(x) % P for x in input().split())
B = sorted(int(x) % P for x in input().split())

B_counter = [0] * P
for b in B:
    B_counter[b] += 1
for i in range(1, P):
    B_counter[i] += B_counter[i - 1]


def lower(x):
    ct = 0
    for a in A:
        b1 = B_counter[x - a] if x - a >= 0 else 0
        b2 = B_counter[P + x - a] if P + x - a < P else N
        assert 0 <= P - a - 1 < P
        ct += b1 + b2 - B_counter[P - a - 1]
    return ct


l, r = -1, P
while r - l > 1:
    m = (r + l) // 2
    if lower(m) >= K:
        r = m
    else:
        l = m
print(r)
0