結果

問題 No.1597 Matrix Sort
ユーザー H3PO4
提出日時 2023-03-29 14:31:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 602 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 174,032 KB
最終ジャッジ日時 2024-09-21 07:19:51
合計ジャッジ時間 8,342 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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:
        i1 = x - a
        if i1 < 0: i1 = 0
        i2 = P + x - a
        if i2 >= P: i2 = P - 1
        
        ct += B_counter[i1] + B_counter[i2] - 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