結果

問題 No.871 かえるのうた
コンテスト
ユーザー SPD_9X2
提出日時 2025-10-15 03:52:25
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WJ  
(最新)
AC  
(最初)
実行時間 -
コード長 722 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
最終ジャッジ日時 2026-10-14 01:08:22
ジャッジサーバーID
(参考情報)
judge4_0 / judge2_0
このコードへのチャレンジ
(要ログイン)

ソースコード

diff #
raw source code

"""

https://yukicoder.me/problems/no/871

範囲が区間になるのを活用するはず

"""

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

L = [ (X[i],A[i]) for i in range(K-1) ]
R = [ (X[i],A[i]) for i in range(K,N) ]
R.reverse()

now = [ X[K-1] - A[K-1] , X[K-1] + A[K-1] ]

flag = True
while flag:

    flag = False
    
    if L and now[0] <= L[-1][0] <= now[1]:
        x,a = L.pop()
        now[0] = min(now[0], x-a)
        now[1] = max(now[1], x+a)
        flag = True

    if R and now[0] <= R[-1][0] <= now[1]:
        x,a = R.pop()
        now[0] = min(now[0], x-a)
        now[1] = max(now[1], x+a)
        flag = True

print (N - len(L) - len(R))
0