結果

問題 No.1597 Matrix Sort
コンテスト
ユーザー rlangevin
提出日時 2023-07-02 02:10:01
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 947 ms / 1,500 ms
コード長 865 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 150 ms
コンパイル使用メモリ 85,500 KB
実行使用メモリ 111,360 KB
最終ジャッジ日時 2026-03-30 05:19:14
合計ジャッジ時間 7,714 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from bisect import *

N, K, P = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split())) + [10 ** 18]
A.sort(reverse=True)
B.sort()
no = -1
yes = P

def check(m):
    cnt = 0
    nowR, nowL = 0, 0
    for a in A:
        while B[nowR] <= m - a:
            nowR += 1
        while nowR - nowL:
            if B[nowL] < -a:
                nowL += 1
            else:
                break
        cnt += nowR - nowL
        
    nowR, nowL = 0, 0
    for a in A:
        while B[nowR] <= m - a + P:
            nowR += 1
        while nowR - nowL:
            if B[nowL] < P - a:
                nowL += 1
            else:
                break
        cnt += nowR - nowL
        
    return cnt >= K


while yes - no != 1:
    mid = (yes + no)//2
    if check(mid):
        yes = mid
    else:
        no = mid
print(yes) 
0