結果

問題 No.2248 max(C)-min(C)
ユーザー shakayamishakayami
提出日時 2023-03-17 22:09:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 940 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 81,892 KB
実行使用メモリ 100,368 KB
最終ジャッジ日時 2024-09-18 11:14:28
合計ジャッジ時間 28,286 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]
X=[(A[i]+B[i])//2 for i in range(N)]
def solve(k):
    #max(C)-min(C)<=kとすることが可能かどうか
    for x in [A[0],B[0],X[0]]:
        MAX=x
        MIN=x
        for i in range(1,N):
            C=[]
            for y in [A[i],B[i],X[i]]:
                if max(MAX,y)-min(MIN,y)<=k:
                    MAX=max(MAX,y)
                    MIN=min(MIN,y)
                    C.append((max(MAX,y)-min(MIN,y),y))
            if len(C)==0:
                MAX=10**18
                MIN=-10**18
                break
            y=min(C)[1]
            MAX=max(MAX,y)
            MIN=min(MIN,y)
            
        if MAX-MIN<=k:
            return True
    return False
low=-1
high=1
while(not(solve(high))):
    high*=2
while(high-low>1):
    mid=(low+high)//2
    if solve(mid):
        high=mid
    else:
        low=mid
print(high)

    
0