結果
| 問題 |
No.1767 BLUE to RED
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-26 23:16:39 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 298 ms / 2,000 ms |
| コード長 | 968 bytes |
| コンパイル時間 | 145 ms |
| コンパイル使用メモリ | 82,480 KB |
| 実行使用メモリ | 133,820 KB |
| 最終ジャッジ日時 | 2024-06-29 18:33:11 |
| 合計ジャッジ時間 | 6,109 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
import sys
input = sys.stdin.readline
def iinput(): return int(input())
def sinput(): return input().rstrip()
def i0input(): return int(input()) - 1
def linput(): return list(input().split())
def liinput(): return list(map(int, input().split()))
def miinput(): return map(int, input().split())
def li0input(): return list(map(lambda x: int(x) - 1, input().split()))
def mi0input(): return map(lambda x: int(x) - 1, input().split())
INF = 10**20
MOD = 1000000007
from bisect import bisect_left
N, M = liinput()
A = liinput()
B = liinput()
ans = 0
if A[0] > B[0]:
ans += A[0] - B[0]
if A[-1] < B[-1]:
ans += B[-1] - A[-1]
if N == 1:
print(ans)
exit()
for a1, a2 in zip(A[:-1], A[1:]):
idx1 = bisect_left(B, a1)
idx2 = bisect_left(B, a2)
m = INF
tmp = [a1]
for i in range(idx1, idx2):
tmp.append(B[i])
tmp.append(a2)
for b1, b2 in zip(tmp[:-1], tmp[1:]):
m = min(m, b1 - a1 + a2 - b2)
ans += m
print(ans)