結果

問題 No.1597 Matrix Sort
ユーザー gr1msl3y
提出日時 2021-11-27 18:07:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 827 ms / 1,500 ms
コード長 529 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,308 KB
実行使用メモリ 489,884 KB
最終ジャッジ日時 2024-06-30 08:56:40
合計ジャッジ時間 14,032 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import accumulate
N, K, P = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ctA = [0]*P
ctB = [0]*P
for a, b in zip(A, B):
    ctA[a] += 1
    ctB[b] += 1

acumB = [0]+list(accumulate(ctB))


def solve(v):
    ct = 0
    for a in A:
        if v >= a:
            ct += acumB[v-a+1]
        ct += acumB[min(P, P+v-a+1)]-acumB[P-a]
    return ct >= K


l, r = -1, P-1
while r-l > 1:
    m = (l+r)//2
    if solve(m):
        r = m
    else:
        l = m

print(r)
0