結果
| 問題 |
No.1767 BLUE to RED
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2021-11-26 23:15:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 868 ms / 2,000 ms |
| コード長 | 618 bytes |
| コンパイル時間 | 165 ms |
| コンパイル使用メモリ | 82,552 KB |
| 実行使用メモリ | 144,020 KB |
| 最終ジャッジ日時 | 2024-06-29 18:32:27 |
| 合計ジャッジ時間 | 13,110 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
import heapq
import bisect
N,M = map(int, input().split())
A = [-10**12]+list(map(int, input().split()))+[10**12]
B = list(map(int, input().split()))
SB = set()
d = []
for i in range(M):
b = B[i]
j = bisect.bisect(A,b)
if A[j]-b>b-A[j-1]:
heapq.heappush(d,(b-A[j-1],i))
else:
heapq.heappush(d,(A[j]-b,i))
ans = 0
while len(d):
v,i = heapq.heappop(d)
if not i in SB:
ans+=v
SB.add(i)
if i>0 and not i-1 in SB:
heapq.heappush(d,(B[i]-B[i-1],i-1))
if i<M-1 and not i+1 in SB:
heapq.heappush(d,(B[i+1]-B[i],i+1))
print(ans)
H20