結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
![]() |
提出日時 | 2023-03-24 11:11:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,937 ms / 3,000 ms |
コード長 | 651 bytes |
コンパイル時間 | 258 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 152,196 KB |
最終ジャッジ日時 | 2024-11-26 13:28:16 |
合計ジャッジ時間 | 56,607 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
import heapqN = int(input())A = list(map(int, input().split()))B = list(map(int, input().split()))C = []mi_max = 10**9for 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_max = min(mi_max,B[i])mi = 10**9ma = 0h = []for i,a in enumerate(A):mi = min(mi,a)ma = max(ma,a)heapq.heappush(h,(a,i,0))ans = ma-miwhile h:before,i,ii= heapq.heappop(h)if ii==0:heapq.heappush(h,((A[i]+B[i])//2,i,1))ma = max(ma,(A[i]+B[i])//2)if ii==1:ma = max(ma,B[i])if len(h):mi=min(h[0][0],mi_max)ans = min(ans,ma-mi)print(ans)