結果

問題 No.2248 max(C)-min(C)
ユーザー flygonflygon
提出日時 2023-03-17 23:03:02
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,413 ms / 3,000 ms
コード長 977 bytes
コンパイル時間 962 ms
コンパイル使用メモリ 81,500 KB
実行使用メモリ 247,840 KB
最終ジャッジ日時 2023-10-18 16:04:05
合計ジャッジ時間 64,324 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,556 KB
testcase_01 AC 43 ms
55,556 KB
testcase_02 AC 43 ms
55,556 KB
testcase_03 AC 67 ms
72,680 KB
testcase_04 AC 62 ms
68,560 KB
testcase_05 AC 56 ms
66,312 KB
testcase_06 AC 82 ms
76,796 KB
testcase_07 AC 81 ms
76,804 KB
testcase_08 AC 85 ms
76,796 KB
testcase_09 AC 86 ms
76,812 KB
testcase_10 AC 56 ms
66,312 KB
testcase_11 AC 84 ms
76,824 KB
testcase_12 AC 69 ms
72,712 KB
testcase_13 AC 78 ms
76,484 KB
testcase_14 AC 83 ms
76,812 KB
testcase_15 AC 83 ms
76,812 KB
testcase_16 AC 66 ms
72,696 KB
testcase_17 AC 83 ms
76,672 KB
testcase_18 AC 2,101 ms
226,272 KB
testcase_19 AC 268 ms
96,828 KB
testcase_20 AC 2,408 ms
247,564 KB
testcase_21 AC 2,273 ms
241,900 KB
testcase_22 AC 1,540 ms
207,000 KB
testcase_23 AC 938 ms
156,680 KB
testcase_24 AC 362 ms
98,624 KB
testcase_25 AC 2,132 ms
237,656 KB
testcase_26 AC 1,870 ms
216,236 KB
testcase_27 AC 2,100 ms
237,096 KB
testcase_28 AC 216 ms
91,244 KB
testcase_29 AC 1,945 ms
221,948 KB
testcase_30 AC 725 ms
136,644 KB
testcase_31 AC 2,382 ms
247,536 KB
testcase_32 AC 411 ms
104,008 KB
testcase_33 AC 671 ms
128,056 KB
testcase_34 AC 2,367 ms
247,840 KB
testcase_35 AC 2,413 ms
247,052 KB
testcase_36 AC 2,395 ms
247,048 KB
testcase_37 AC 1,171 ms
178,684 KB
testcase_38 AC 2,275 ms
232,296 KB
testcase_39 AC 2,301 ms
232,300 KB
testcase_40 AC 2,273 ms
232,300 KB
testcase_41 AC 1,879 ms
204,336 KB
testcase_42 AC 2,255 ms
232,292 KB
testcase_43 AC 1,961 ms
205,720 KB
testcase_44 AC 2,278 ms
231,944 KB
testcase_45 AC 1,719 ms
212,428 KB
testcase_46 AC 860 ms
146,268 KB
testcase_47 AC 2,244 ms
232,292 KB
testcase_48 AC 408 ms
159,260 KB
testcase_49 AC 2,136 ms
243,408 KB
testcase_50 AC 2,147 ms
243,676 KB
testcase_51 AC 2,165 ms
243,676 KB
testcase_52 AC 2,135 ms
243,684 KB
testcase_53 AC 340 ms
98,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
    




0