結果

問題 No.1767 BLUE to RED
ユーザー roarisroaris
提出日時 2021-12-17 19:40:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 474 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 136,352 KB
最終ジャッジ日時 2023-10-12 22:54:48
合計ジャッジ時間 6,814 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
70,896 KB
testcase_01 AC 70 ms
70,988 KB
testcase_02 AC 71 ms
71,068 KB
testcase_03 AC 73 ms
71,036 KB
testcase_04 AC 73 ms
70,896 KB
testcase_05 AC 74 ms
71,060 KB
testcase_06 AC 73 ms
71,120 KB
testcase_07 AC 77 ms
75,292 KB
testcase_08 AC 77 ms
75,552 KB
testcase_09 AC 153 ms
98,172 KB
testcase_10 AC 168 ms
103,592 KB
testcase_11 AC 155 ms
98,888 KB
testcase_12 AC 152 ms
98,232 KB
testcase_13 AC 177 ms
122,436 KB
testcase_14 AC 200 ms
134,856 KB
testcase_15 AC 200 ms
135,756 KB
testcase_16 AC 197 ms
135,652 KB
testcase_17 AC 194 ms
135,984 KB
testcase_18 AC 196 ms
135,840 KB
testcase_19 AC 196 ms
135,704 KB
testcase_20 AC 203 ms
135,828 KB
testcase_21 AC 200 ms
136,352 KB
testcase_22 AC 200 ms
135,856 KB
testcase_23 AC 202 ms
135,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = [-10**18]+list(map(int, input().split()))+[10**18]
B = list(map(int, input().split()))
B.reverse()
ans = 0

for i in range(N+1):
    l = []
    
    while B and A[i]<=B[-1]<=A[i+1]:
        l.append(B.pop())
    
    if len(l)==0:
        continue
    
    v = min(l[-1]-A[i], A[i+1]-l[0])
    
    for j in range(len(l)-1):
        v = min(v, l[j]-A[i]+A[i+1]-l[j+1])
    
    ans += v

print(ans)
0