結果

問題 No.3325 陰陽師
コンテスト
ユーザー 高橋ゆに
提出日時 2025-11-01 03:01:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 882 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 82,896 KB
実行使用メモリ 152,424 KB
最終ジャッジ日時 2025-11-01 14:26:26
合計ジャッジ時間 16,667 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

STAND_TOTAL, GHOST_TOTAL = map(int, input().split())
STRENGTHS = list(map(int, input().split()))
TARGETS = list(map(int, input().split()))

assert(1 <= GHOST_TOTAL <= STAND_TOTAL <= 2*(10**5))
assert(STAND_TOTAL == len(STRENGTHS))
assert(GHOST_TOTAL == len(TARGETS))
assert(all(1 <= STRENGTHS[i] <= 10**9 for i in range(STAND_TOTAL)))
assert(all(1 <= TARGETS[i] <= 10**9 for i in range(GHOST_TOTAL)))


def main():
    STRENGTHS.sort()
    
    ok, ng = 0, GHOST_TOTAL + 1
    while abs(ok - ng) > 1:
        med = (ok + ng) // 2
        if judge(med) > -1:
            ok = med
        else:
            ng = med
    
    print(judge(ok))

def judge(x):
    if x == 0:
        return 0
        
    sub_targets = [TARGETS[case_i] for case_i in range(x)]
    sub_targets.sort()
    
    res = 0
    ghost_i = 0
    for strength in STRENGTHS:
        target = sub_targets[ghost_i]
        if strength >= target:
            ghost_i += 1
            res = max(res, strength - target)
            if ghost_i >= x:
                break
        
    if ghost_i >= x:
        return res
    else:
        return -1

if __name__ == "__main__":
    main()
0