結果
| 問題 |
No.2248 max(C)-min(C)
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2023-03-17 22:40:05 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 750 bytes |
| コンパイル時間 | 491 ms |
| コンパイル使用メモリ | 82,244 KB |
| 実行使用メモリ | 244,032 KB |
| 最終ジャッジ日時 | 2024-09-18 11:49:13 |
| 合計ジャッジ時間 | 65,877 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 4 WA * 26 RE * 21 |
ソースコード
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:
mi=h[0][0]
ans = min(ans,ma-mi)
print(ans)
H20