結果

問題 No.1767 BLUE to RED
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-11-26 22:44:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 558 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 136,216 KB
最終ジャッジ日時 2023-09-12 05:18:40
合計ジャッジ時間 6,236 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
70,992 KB
testcase_01 AC 77 ms
70,996 KB
testcase_02 AC 80 ms
71,380 KB
testcase_03 AC 76 ms
71,236 KB
testcase_04 AC 78 ms
71,296 KB
testcase_05 AC 81 ms
71,188 KB
testcase_06 AC 79 ms
71,376 KB
testcase_07 AC 96 ms
76,144 KB
testcase_08 AC 94 ms
76,692 KB
testcase_09 AC 179 ms
98,108 KB
testcase_10 AC 208 ms
103,468 KB
testcase_11 AC 183 ms
98,960 KB
testcase_12 AC 180 ms
97,860 KB
testcase_13 AC 228 ms
123,300 KB
testcase_14 AC 250 ms
135,968 KB
testcase_15 AC 258 ms
135,656 KB
testcase_16 AC 255 ms
135,920 KB
testcase_17 AC 252 ms
135,920 KB
testcase_18 AC 249 ms
135,664 KB
testcase_19 AC 248 ms
136,008 KB
testcase_20 AC 244 ms
136,192 KB
testcase_21 AC 256 ms
135,980 KB
testcase_22 AC 245 ms
136,216 KB
testcase_23 AC 248 ms
135,892 KB
権限があれば一括ダウンロードができます

ソースコード

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