結果

問題 No.1767 BLUE to RED
ユーザー SPD_9X2
提出日時 2021-11-26 22:44:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 82,196 KB
実行使用メモリ 135,236 KB
最終ジャッジ日時 2024-06-29 18:18:39
合計ジャッジ時間 4,070 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

"""

import sys
from sys import stdin

N,M = map(int,stdin.readline().split())

A = [-10**10] + list(map(int,stdin.readline().split())) + [10**10]
B = list(map(int,stdin.readline().split()))

B.reverse()

ans = 0
for i in range(N+1):

    al = A[i]
    ar = A[i+1]

    dlis = [al]
    while len(B) > 0 and al <= B[-1] <= ar:
        dlis.append(B[-1])
        del B[-1]

    dlis.append(ar)

    d2 = []
    for j in range(len(dlis)-1):
        d2.append(dlis[j+1]-dlis[j])

    #print (al,ar,d2)
    ma = max(d2)
    ans += sum(d2) - ma

print (ans)
0