結果

問題 No.1767 BLUE to RED
ユーザー SidewaysOwl
提出日時 2021-11-27 09:44:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 82,280 KB
実行使用メモリ 145,172 KB
最終ジャッジ日時 2024-06-30 01:27:18
合計ジャッジ時間 6,081 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
a = [-(10**9 + 1)] + list(map(int,input().split())) + [2*10**9 + 1] 
b = list(map(int,input().split()))
ab = []
for i in range(n+2):
    ab.append([a[i],1])
for i in range(m):
    ab.append([b[i],0])
ab.sort()
flg = 1
max_ = 0
sum_ = 0
ans = 0
for i in range(n+m+2):
    idx,color = ab[i]
    if color == 1 and flg == 0:
        max_ = max(ab[i][0] - ab[i-1][0] ,max_)
        sum_ += ab[i][0] - ab[i-1][0]
        ans += sum_ - max_
    elif color == 0 and flg == 1:
        max_ = ab[i][0] - ab[i-1][0]
        sum_ = ab[i][0] - ab[i-1][0]
    elif color == 0 and flg == 0:
        max_ = max(ab[i][0] - ab[i-1][0] ,max_)
        sum_ += ab[i][0] - ab[i-1][0]
    flg = color
    
print(ans)
0