結果
| 問題 | No.2248 max(C)-min(C) |
| コンテスト | |
| ユーザー |
hir355
|
| 提出日時 | 2023-03-17 22:41:30 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 1,569 ms / 3,000 ms |
| コード長 | 646 bytes |
| 記録 | |
| コンパイル時間 | 123 ms |
| コンパイル使用メモリ | 84,992 KB |
| 実行使用メモリ | 152,404 KB |
| 最終ジャッジ日時 | 2026-04-06 16:17:19 |
| 合計ジャッジ時間 | 21,960 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 51 |
ソースコード
import heapq
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
if a[i] > b[i]:
a[i], b[i] = b[i], a[i]
hq = []
for i in range(n):
heapq.heappush(hq, (a[i], i, 0))
ma = max(a)
ans = max(a) - min(a)
for _ in range(n * 2):
x, i, j = heapq.heappop(hq)
if ans > ma - x:
ans = ma - x
if j == 0:
heapq.heappush(hq, ((a[i] + b[i]) // 2, i, 1))
if ma < (a[i] + b[i]) // 2:
ma = (a[i] + b[i]) // 2
elif j == 1:
heapq.heappush(hq, (b[i], i, 2))
if ma < b[i]:
ma = b[i]
else:
break
print(ans)
hir355