結果

問題 No.871 かえるのうた
ユーザー tktk_snsn
提出日時 2021-02-07 19:37:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 82,228 KB
実行使用メモリ 100,848 KB
最終ジャッジ日時 2024-11-30 11:05:06
合計ジャッジ時間 4,444 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
inf = float("inf")
X = [-inf] + list(map(int, input().split())) + [inf]
A = [-1] + list(map(int, input().split())) + [inf]

ans = [0] * (N + 2)

# left
L = X[K]
R = X[K]
i = K
j = K
while i or j < N + 1:
    if i and X[i] >= L:
        ans[i] = 1
        L = min(L, X[i] - A[i])
        R = max(R, X[i] + A[i])
        i -= 1
        continue
    if j < N + 1 and X[j] <= R:
        ans[j] = 1
        L = min(L, X[j] - A[j])
        R = max(R, X[j] + A[j])
        j += 1
        continue
    break


print(sum(ans))
0