結果

問題 No.1767 BLUE to RED
コンテスト
ユーザー 👑 SPD_9X2
提出日時 2021-11-26 22:44:27
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 558 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 384 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 115,840 KB
最終ジャッジ日時 2026-03-19 08:21:31
合計ジャッジ時間 3,614 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

"""

"""

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