結果

問題 No.1597 Matrix Sort
ユーザー convexineqconvexineq
提出日時 2021-07-09 21:52:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 323 ms / 1,500 ms
コード長 667 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 104,904 KB
最終ジャッジ日時 2024-07-01 16:04:43
合計ジャッジ時間 7,344 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

n,k,p = map(int,readline().split())
*a, = map(int,readline().split())
*b, = map(int,readline().split())
a.sort()
b.sort()

def check(x): # x 以下の数は k 個以上か?
    res = 0
    R = L1 = R1 = n-1
    for ai in a:
        while R >= 0 and ai+b[R] > x:
            R -= 1
        res += R+1
        
        while L1 >= 0 and ai+b[L1] >= p:
            L1 -= 1
        while R1 >= 0 and ai+b[R1] > p+x:
            R1 -= 1
        res += R1-L1
        #print(R,L1,R1)
    return res >= k

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