結果
| 問題 | No.2248 max(C)-min(C) | 
| コンテスト | |
| ユーザー |  timi | 
| 提出日時 | 2023-03-20 12:04:39 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,254 ms / 3,000 ms | 
| コード長 | 1,028 bytes | 
| コンパイル時間 | 245 ms | 
| コンパイル使用メモリ | 82,200 KB | 
| 実行使用メモリ | 308,620 KB | 
| 最終ジャッジ日時 | 2024-09-18 14:02:03 | 
| 合計ジャッジ時間 | 24,471 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 51 | 
ソースコード
def main():
  from sys import stdin, setrecursionlimit
  input = stdin.readline
  readline = stdin.readline
  N=int(input())
  A=list(map(int, input().split()))
  B=list(map(int, input().split()))
  if N==1:
    print(0)
    exit()
  import sys
  input = sys.stdin.readline
  D={}
  E=[]
  import heapq
  Q=[]
  for i in range(N):
    a,b,c=A[i],B[i],(A[i]+B[i])//2
    E.append(a)
    E.append(b)
    E.append(c)
    if a!=b:
      a,b,c=sorted([a,b,c])[::-1]
      heapq.heappush(Q,a) 
      if a not in D:
        D[a]=[]
      D[a].append(b)
      if b not in D:
        D[b]=[]
      D[b].append(c)
      if c not in D:
        D[c]=[]
      D[c].append(-1)
    else:
      heapq.heappush(Q,a) 
      if a not in D:
        D[a]=[]
      D[a].append(-1)
  #print(Q,D)
  E=sorted(list(set(E)))[::-1]
  #print(E)
  ans=10**12
  for e in E:
    mi=heapq.heappop(Q)
    ans=min(ans,e-mi)
    heapq.heappush(Q,mi)
    for nex in D[e]:
      if nex==-1:
        print(ans)
        exit()
      heapq.heappush(Q,nex)
    
main()
            
            
            
        