結果

問題 No.2248 max(C)-min(C)
コンテスト
ユーザー ikoma
提出日時 2023-03-18 01:20:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 810 ms / 3,000 ms
コード長 607 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 304 ms
コンパイル使用メモリ 81,860 KB
実行使用メモリ 143,736 KB
最終ジャッジ日時 2024-09-18 12:49:27
合計ジャッジ時間 16,492 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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