結果
問題 |
No.2248 max(C)-min(C)
|
ユーザー |
|
提出日時 | 2023-03-22 00:07:35 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 669 ms / 3,000 ms |
コード長 | 666 bytes |
コンパイル時間 | 713 ms |
コンパイル使用メモリ | 82,104 KB |
実行使用メモリ | 143,876 KB |
最終ジャッジ日時 | 2024-09-18 14:35:07 |
合計ジャッジ時間 | 14,132 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
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)