結果
| 問題 | No.1597 Matrix Sort | 
| コンテスト | |
| ユーザー |  ayaoni | 
| 提出日時 | 2021-07-09 21:57:30 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 969 ms / 1,500 ms | 
| コード長 | 877 bytes | 
| コンパイル時間 | 163 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 387,764 KB | 
| 最終ジャッジ日時 | 2024-07-01 16:15:28 | 
| 合計ジャッジ時間 | 18,384 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
import sys
from itertools import accumulate
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())
N,K,P = MI()
A = LI()
B = LI()
count = [0]*P
for b in B:
    count[b] += 1
S_count = list(accumulate(count))
ng = -1
ok = P-1
while ng+1 < ok:
    mid = (ng+ok)//2
    c = 0
    for i in range(N):
        a = A[i]
        if mid >= a:
            c += S_count[mid-a]
        c += S_count[min(P-1,P+mid-a)]-S_count[P-a-1]
    if c >= K:
        ok = mid
    else:
        ng = mid
print(ok)
            
            
            
        