結果

問題 No.2248 max(C)-min(C)
コンテスト
ユーザー lloyz
提出日時 2023-03-22 00:07:35
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 465 ms / 3,000 ms
+ 222µs
コード長 666 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 84 ms
コンパイル使用メモリ 64,244 KB
実行使用メモリ 100,504 KB
最終ジャッジ日時 2026-11-08 10:45:02
合計ジャッジ時間 13,507 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 53
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from heapq import heapify, heappop, heappush
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
M = []
for i in range(n):
    if A[i] > B[i]:
        A[i], B[i] = B[i], A[i]
    M.append((A[i] + B[i]) // 2)
H = []
max_ = -10**18
for i in range(n):
    heappush(H, (A[i], i))
    max_ = max(max_, A[i])
ans = max_ - H[0][0]
while True:
    x, i = heappop(H)
    if x == B[i]:
        break
    elif x == M[i]:
        heappush(H, (B[i], i))
        max_ = max(max_, B[i])
    else:
        heappush(H, (M[i], i))
        max_ = max(max_, M[i])
    ans = min(ans, max_ - H[0][0])
print(ans)
0