結果

問題 No.1597 Matrix Sort
コンテスト
ユーザー 回転
提出日時 2025-11-14 03:30:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,148 ms / 1,500 ms
コード長 957 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 82,704 KB
実行使用メモリ 250,620 KB
最終ジャッジ日時 2025-11-14 03:31:17
合計ジャッジ時間 15,408 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
from functools import cache
N,K,P = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.sort()
B.sort()

memo_l = [-1 for _ in range(P+1)]
def memo_bisect_left(p):
    if(p >= P):return N
    if(p < 0):return 0
    if(memo_l[p] != -1):return memo_l[p]
    memo_l[p] = bisect.bisect_left(B,p)
    return memo_l[p]

memo_r = [-1 for _ in range(P)]
def memo_bisect_right(p):
    if(p >= P):return N
    if(p < 0):return 0
    if(memo_r[p] != -1):return memo_r[p]
    memo_r[p] = bisect.bisect_right(B,p)
    return memo_r[p]

def check(n):
    count = 0
    for i in A:
        left = memo_bisect_left(P-i)
        right = memo_bisect_right(n+P-i)
        count += right - left

        right2 = memo_bisect_right(n-i)
        count += right2
    return count >= K

ng,ok = -1,P-1
while(ok - ng > 1):
    mid = (ok+ng)//2
    if(check(mid)):
        ok = mid
    else:
        ng = mid
print(ok)
0