結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
|
提出日時 | 2023-03-17 22:58:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,313 ms / 3,000 ms |
コード長 | 578 bytes |
コンパイル時間 | 296 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 146,592 KB |
最終ジャッジ日時 | 2024-12-20 10:08:22 |
合計ジャッジ時間 | 32,604 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) pq = [] for i in range(N): if A[i] > B[i]: A[i],B[i]=B[i],A[i] pq.append([A[i], i, 0]) from heapq import * hi = max(x for x,i,j in pq) heapify(pq) ans = hi - pq[0][0] while pq: x,i,j = heappop(pq) if j == 2: break if j == 0: x = A[i] + B[i] >> 1 hi = max(hi, x) heappush(pq, [x,i,j+1]) if j == 1: x = B[i] hi = max(hi, x) heappush(pq, [x,i,j+1]) if pq: ans = min(ans, hi - pq[0][0]) print(ans)