結果

問題 No.871 かえるのうた
ユーザー norioc
提出日時 2025-02-17 04:41:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 638 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 81,856 KB
実行使用メモリ 96,580 KB
最終ジャッジ日時 2025-02-17 04:41:52
合計ジャッジ時間 5,004 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N, K = map(int, input().split())
K -= 1
X = list(map(int, input().split()))
A = list(map(int, input().split()))

left = X[K] - A[K]
right = X[K] + A[K]
q = deque([K])
update = True
while update:
    update = False

    hd = q[0]
    if hd > 0 and left <= X[hd-1]:
        update = True
        left = min(left, X[hd-1] - A[hd-1])
        right = max(right, X[hd-1] + A[hd-1])
        q.appendleft(hd-1)

    tl = q[-1]
    if tl+1 < N and X[tl+1] <= right:
        update = True
        left = min(left, X[tl+1] - A[tl+1])
        right = max(right, X[tl+1] + A[tl+1])
        q.append(tl+1)

print(len(q))
0