結果
問題 | No.2248 max(C)-min(C) |
ユーザー |
|
提出日時 | 2023-03-17 23:03:02 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,510 ms / 3,000 ms |
コード長 | 977 bytes |
コンパイル時間 | 238 ms |
コンパイル使用メモリ | 82,544 KB |
実行使用メモリ | 248,452 KB |
最終ジャッジ日時 | 2024-09-18 12:10:27 |
合計ジャッジ時間 | 66,029 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) c = [(a[i]+b[i])//2 for i in range(n)] all = [(a[i], i) for i in range(n)] + [(b[i], i) for i in range(n)] + [(c[i], i) for i in range(n)] s = sorted(list(set(a + b + c))) all.sort() m = len(s) r = 0 ll = 0 rr = 0 d = defaultdict(int) now = 0 ans = float("inf") for l in range(m): while r < m and now != n: while rr < 3*n and all[rr][0] == s[r]: d[all[rr][1]] += 1 now += (d[all[rr][1]] == 1) rr += 1 r += 1 if now == n: ans = min(ans, s[r-1] - s[l]) while ll < 3*n and all[ll][0] == s[l]: d[all[ll][1]] -= 1 now -=(d[all[ll][1]] == 0) ll += 1 print(ans)