結果

問題 No.1597 Matrix Sort
ユーザー H3PO4
提出日時 2023-03-29 14:58:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 615 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 173,424 KB
最終ジャッジ日時 2024-09-21 07:36:42
合計ジャッジ時間 8,075 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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 = 0, P
while r - l > 1:
    m = (r + l) // 2
    if lower(m) >= K:
        r = m
    else:
        l = m
print(l + 1)
0