結果

問題 No.1767 BLUE to RED
ユーザー gr1msl3ygr1msl3y
提出日時 2021-11-26 22:59:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 601 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 86,560 KB
実行使用メモリ 139,856 KB
最終ジャッジ日時 2023-09-12 05:25:37
合計ジャッジ時間 7,012 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,320 KB
testcase_01 AC 74 ms
71,236 KB
testcase_02 AC 73 ms
71,124 KB
testcase_03 AC 75 ms
71,180 KB
testcase_04 AC 80 ms
75,176 KB
testcase_05 AC 81 ms
75,244 KB
testcase_06 AC 74 ms
71,148 KB
testcase_07 AC 81 ms
76,024 KB
testcase_08 AC 83 ms
76,224 KB
testcase_09 AC 203 ms
107,868 KB
testcase_10 AC 242 ms
119,968 KB
testcase_11 AC 217 ms
112,096 KB
testcase_12 AC 204 ms
107,848 KB
testcase_13 AC 259 ms
131,728 KB
testcase_14 AC 291 ms
139,468 KB
testcase_15 AC 287 ms
139,524 KB
testcase_16 AC 287 ms
139,580 KB
testcase_17 AC 290 ms
139,768 KB
testcase_18 AC 295 ms
139,504 KB
testcase_19 AC 286 ms
139,532 KB
testcase_20 AC 297 ms
139,716 KB
testcase_21 AC 292 ms
139,856 KB
testcase_22 AC 292 ms
139,504 KB
testcase_23 AC 293 ms
139,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

C = [[] for _ in range(N+1)]
for i in range(N):
    C[i+1].append(A[i])

for b in B:
    ind = bisect(A, b)
    C[ind].append(b)
for i in range(N):
    C[i].append(A[i])

ans = 0
for i in range(1, N):
    if len(C[i]) == 2:
        continue
    L = C[i][-1]-C[i][0]
    v = L
    for j in range(len(C[i])-1):
        v = min(v, L-(C[i][j+1]-C[i][j]))
    ans += v

if len(C[0]) > 1:
    ans += C[0][-1]-C[0][0]
if len(C[N]) > 1:
    ans += C[N][-1]-C[N][0]

print(ans)
0