結果

問題 No.1597 Matrix Sort
コンテスト
ユーザー Navier_Boltzmann
提出日時 2022-02-06 17:31:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 674 bytes
コンパイル時間 429 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 180,988 KB
最終ジャッジ日時 2024-06-11 13:51:05
合計ジャッジ時間 10,346 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K,P = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
A.sort()
B.sort()
from collections import Counter
c = Counter(B)
F = [0]*(P+1)
for i in range(1,P):
    F[i+1] = F[i] + c[i]
def is_ok(x):
    tmp = 0
    for a in A:
        if 0<=x-a<=P-1:
            tmp += F[x-a+1] - F[0]
            
        if P-a <= P-1:
            tmp += F[min(P-1,P+x-a)+1] - F[P-a]
        
    return tmp >= K
            
            
y = P-1
if P == 1:
    print(0)
    exit()
x = 0
if is_ok(0):
    print(0)
    exit()
while y-x>1:
    mid = (y+x)//2
    
    if is_ok(mid):
        y = mid
    else:
        x = mid
print(y)
        
    
0