結果

問題 No.2248 max(C)-min(C)
ユーザー H20
提出日時 2023-03-17 22:44:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 761 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 243,796 KB
最終ジャッジ日時 2024-09-18 11:55:01
合計ジャッジ時間 65,834 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import collections
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(N):
    if A[i]>B[i]:
        A[i],B[i]=B[i],A[i]
    C.append([A[i],(A[i]+B[i])//2,B[i]])

mi = 10**9
ma = 0
h = []
COL = collections.Counter()
for i,a in enumerate(A):
    mi = min(mi,a)
    ma = max(ma,a)
    heapq.heappush(h,(a,i,0))
    COL[a]+=1
ans = ma-mi
while h:
    before,i,ii= heapq.heappop(h)
    COL[before]-=1
    if ii==0:
        heapq.heappush(h,((A[i]+B[i])//2,i,1))
        ma = max(ma,(A[i]+B[i])//2)
        COL[(A[i]+B[i])//2]+=1
    if ii==1:
        ma = max(ma,B[i])
        COL[B[i]]+=1
    if COL[before]==0 and mi==before and len(h):
        mi=h[0][0]
    ans = min(ans,ma-mi)
print(ans)
0