結果
問題 |
No.1767 BLUE to RED
|
ユーザー |
|
提出日時 | 2021-12-17 19:40:42 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 195 ms / 2,000 ms |
コード長 | 474 bytes |
コンパイル時間 | 166 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 135,104 KB |
最終ジャッジ日時 | 2024-09-14 21:05:06 |
合計ジャッジ時間 | 6,031 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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)