結果

問題 No.2248 max(C)-min(C)
コンテスト
ユーザー ikoma
提出日時 2023-03-18 01:20:35
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 452 ms / 3,000 ms
コード長 607 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 160 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 142,628 KB
最終ジャッジ日時 2026-04-06 16:42:09
合計ジャッジ時間 10,862 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
from heapq import *
INF=1<<60
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
M=[]
mx=-INF
for i in range(N):
    if A[i]>B[i]:A[i],B[i]=B[i],A[i]
    M.append(A[i]+B[i]>>1)
heap=[]
for i,a in enumerate(A):
    heappush(heap, (a,i))
    mx = max(mx,a)
ans=mx-heap[0][0]
while True:
    x,i = heappop(heap)
    if x==B[i]:break
    if x==M[i]:
        b=B[i]
        heappush(heap, (b,i))
        mx = max(mx,b)
    else:
        m = M[i]
        heappush(heap, (m,i))
        mx = max(mx,m)
    ans = min(ans, mx-heap[0][0])

print(ans)
0