結果

問題 No.1597 Matrix Sort
ユーザー titia
提出日時 2025-05-13 04:38:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,136 ms / 1,500 ms
コード長 674 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 103,068 KB
最終ジャッジ日時 2025-05-13 04:38:38
合計ジャッジ時間 22,926 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from bisect import bisect,bisect_left

N,K,P=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A.sort()
B.sort()

OK=P-1
NG=-1

while OK>NG+1:
    mid=(OK+NG)//2

    ANS=0

    for a in A:
        if a+B[0]<=mid:
            x=bisect(B,mid-a)
            y=bisect_left(B,P-a)
            ANS+=x+(N-y)
        elif (a+B[0])%P<=mid:
            x=bisect(B,mid-a+P)
            ANS+=x
        else:
            x=bisect_left(B,P-a)
            y=bisect(B,P+mid-a)
            ANS+=y-x

        #print(a,ANS)

    #print(mid,ANS)

    if ANS>=K:
        OK=mid
    else:
        NG=mid

print(OK)
0