結果

問題 No.2248 max(C)-min(C)
ユーザー flygonflygon
提出日時 2023-03-17 23:06:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,300 ms / 3,000 ms
コード長 1,006 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 81,716 KB
実行使用メモリ 247,936 KB
最終ジャッジ日時 2023-10-18 16:07:24
合計ジャッジ時間 61,552 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,672 KB
testcase_01 AC 43 ms
55,672 KB
testcase_02 AC 43 ms
55,672 KB
testcase_03 AC 61 ms
70,724 KB
testcase_04 AC 54 ms
66,584 KB
testcase_05 AC 51 ms
64,348 KB
testcase_06 AC 77 ms
76,744 KB
testcase_07 AC 76 ms
76,868 KB
testcase_08 AC 78 ms
76,880 KB
testcase_09 AC 77 ms
76,884 KB
testcase_10 AC 51 ms
64,348 KB
testcase_11 AC 78 ms
76,912 KB
testcase_12 AC 62 ms
70,748 KB
testcase_13 AC 68 ms
72,920 KB
testcase_14 AC 77 ms
76,900 KB
testcase_15 AC 78 ms
76,892 KB
testcase_16 AC 61 ms
70,724 KB
testcase_17 AC 76 ms
76,760 KB
testcase_18 AC 1,946 ms
226,372 KB
testcase_19 AC 252 ms
96,904 KB
testcase_20 AC 2,274 ms
247,640 KB
testcase_21 AC 2,158 ms
242,004 KB
testcase_22 AC 1,434 ms
207,096 KB
testcase_23 AC 895 ms
156,776 KB
testcase_24 AC 350 ms
98,720 KB
testcase_25 AC 2,010 ms
237,752 KB
testcase_26 AC 1,773 ms
216,340 KB
testcase_27 AC 1,995 ms
237,212 KB
testcase_28 AC 204 ms
91,308 KB
testcase_29 AC 1,828 ms
222,052 KB
testcase_30 AC 698 ms
136,748 KB
testcase_31 AC 2,300 ms
247,660 KB
testcase_32 AC 409 ms
104,152 KB
testcase_33 AC 642 ms
128,156 KB
testcase_34 AC 2,220 ms
247,936 KB
testcase_35 AC 2,225 ms
247,144 KB
testcase_36 AC 2,248 ms
247,148 KB
testcase_37 AC 1,113 ms
178,784 KB
testcase_38 AC 2,168 ms
232,392 KB
testcase_39 AC 2,205 ms
232,400 KB
testcase_40 AC 2,173 ms
232,400 KB
testcase_41 AC 1,838 ms
204,436 KB
testcase_42 AC 2,200 ms
232,392 KB
testcase_43 AC 1,896 ms
205,820 KB
testcase_44 AC 2,191 ms
232,044 KB
testcase_45 AC 1,657 ms
212,524 KB
testcase_46 AC 852 ms
146,368 KB
testcase_47 AC 2,154 ms
232,392 KB
testcase_48 AC 395 ms
159,360 KB
testcase_49 AC 2,093 ms
243,504 KB
testcase_50 AC 2,066 ms
244,036 KB
testcase_51 AC 2,071 ms
243,820 KB
testcase_52 AC 2,057 ms
243,780 KB
testcase_53 AC 345 ms
98,688 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])
    if now < n: break
    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