結果

問題 No.1767 BLUE to RED
ユーザー suosuo
提出日時 2021-11-26 22:54:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 507 bytes
コンパイル時間 1,212 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 142,760 KB
最終ジャッジ日時 2023-09-12 05:22:23
合計ジャッジ時間 7,494 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,196 KB
testcase_01 AC 77 ms
71,352 KB
testcase_02 AC 80 ms
71,224 KB
testcase_03 AC 77 ms
70,968 KB
testcase_04 AC 82 ms
71,252 KB
testcase_05 AC 89 ms
75,568 KB
testcase_06 AC 80 ms
71,428 KB
testcase_07 AC 95 ms
76,144 KB
testcase_08 AC 94 ms
75,948 KB
testcase_09 AC 223 ms
98,404 KB
testcase_10 AC 255 ms
105,332 KB
testcase_11 AC 222 ms
103,376 KB
testcase_12 AC 218 ms
99,068 KB
testcase_13 AC 293 ms
127,844 KB
testcase_14 AC 311 ms
142,336 KB
testcase_15 AC 308 ms
142,488 KB
testcase_16 AC 314 ms
142,448 KB
testcase_17 AC 310 ms
142,340 KB
testcase_18 AC 314 ms
142,632 KB
testcase_19 AC 314 ms
142,760 KB
testcase_20 AC 311 ms
142,256 KB
testcase_21 AC 312 ms
142,492 KB
testcase_22 AC 312 ms
142,644 KB
testcase_23 AC 312 ms
142,660 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

n,m = map(int,input().split())
a = [-10**9] + list(map(int,input().split())) + [2*10**9+1]
b = [-10**9] + list(map(int,input().split())) + [2*10**9+1]
ans = 0
for i in range(n+1):
    mi,ma = a[i],a[i+1]
    l = bisect.bisect_right(b,mi)
    r = bisect.bisect_left(b,ma) - 1
    while l <= r:
        if b[l] - mi < ma - b[r]:
            ans += b[l] - mi
            mi = b[l]
            l += 1
        else:
            ans += ma - b[r]
            ma = b[r]
            r -= 1
print(ans)
0