結果

問題 No.1767 BLUE to RED
ユーザー O2MTO2MT
提出日時 2021-12-11 23:29:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 504 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,316 KB
実行使用メモリ 138,636 KB
最終ジャッジ日時 2023-09-27 12:49:00
合計ジャッジ時間 6,167 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
71,616 KB
testcase_01 AC 61 ms
71,460 KB
testcase_02 AC 61 ms
71,540 KB
testcase_03 AC 60 ms
71,324 KB
testcase_04 AC 63 ms
75,396 KB
testcase_05 AC 66 ms
75,500 KB
testcase_06 AC 61 ms
71,352 KB
testcase_07 AC 66 ms
76,312 KB
testcase_08 AC 67 ms
76,128 KB
testcase_09 AC 151 ms
96,824 KB
testcase_10 AC 169 ms
105,336 KB
testcase_11 AC 162 ms
100,204 KB
testcase_12 AC 154 ms
96,752 KB
testcase_13 AC 194 ms
124,884 KB
testcase_14 AC 258 ms
137,920 KB
testcase_15 AC 253 ms
138,244 KB
testcase_16 AC 220 ms
138,432 KB
testcase_17 AC 219 ms
138,184 KB
testcase_18 AC 224 ms
138,368 KB
testcase_19 AC 227 ms
138,240 KB
testcase_20 AC 223 ms
138,216 KB
testcase_21 AC 221 ms
138,636 KB
testcase_22 AC 221 ms
138,404 KB
testcase_23 AC 220 ms
138,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left

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

C = []
i = -1
ans = 0
c = 0
b_cp = 0

def plus_num():
  global ans
  ans += A[i]-A[i-1]-max(c,abs(A[i]-b_cp))

for b in B:
  bis = bisect_left(A,b)
  if bis == i:
    C.append(b)
    c = max(c,C[-1]-C[-2])
  else:
    if C:
      plus_num()
      C = []
    i = bis
    c = abs(b-A[i-1])
    C.append(b)
  b_cp = b
if C:
  plus_num()
print(ans)
0