結果

問題 No.871 かえるのうた
ユーザー FromBooskaFromBooska
提出日時 2023-10-17 11:59:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,209 bytes
コンパイル時間 1,007 ms
コンパイル使用メモリ 81,432 KB
実行使用メモリ 98,064 KB
最終ジャッジ日時 2023-10-17 11:59:16
合計ジャッジ時間 7,801 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,372 KB
testcase_01 AC 37 ms
53,372 KB
testcase_02 AC 38 ms
53,372 KB
testcase_03 AC 37 ms
53,372 KB
testcase_04 AC 37 ms
53,372 KB
testcase_05 AC 38 ms
53,372 KB
testcase_06 AC 38 ms
53,372 KB
testcase_07 AC 38 ms
53,372 KB
testcase_08 AC 44 ms
59,284 KB
testcase_09 AC 41 ms
59,308 KB
testcase_10 AC 43 ms
59,308 KB
testcase_11 AC 41 ms
59,308 KB
testcase_12 AC 48 ms
67,656 KB
testcase_13 AC 43 ms
61,356 KB
testcase_14 AC 91 ms
92,772 KB
testcase_15 AC 89 ms
92,688 KB
testcase_16 AC 102 ms
93,900 KB
testcase_17 AC 86 ms
94,472 KB
testcase_18 AC 47 ms
68,156 KB
testcase_19 AC 98 ms
93,412 KB
testcase_20 AC 50 ms
66,352 KB
testcase_21 AC 74 ms
84,948 KB
testcase_22 AC 37 ms
53,380 KB
testcase_23 AC 38 ms
53,380 KB
testcase_24 AC 37 ms
53,380 KB
testcase_25 AC 46 ms
61,812 KB
testcase_26 AC 48 ms
63,860 KB
testcase_27 AC 46 ms
65,988 KB
testcase_28 AC 37 ms
53,380 KB
testcase_29 AC 62 ms
86,992 KB
testcase_30 AC 88 ms
97,232 KB
testcase_31 AC 41 ms
59,308 KB
testcase_32 AC 82 ms
94,404 KB
testcase_33 AC 90 ms
95,620 KB
testcase_34 AC 50 ms
69,912 KB
testcase_35 AC 67 ms
88,736 KB
testcase_36 AC 81 ms
98,064 KB
testcase_37 AC 69 ms
85,216 KB
testcase_38 AC 96 ms
94,616 KB
testcase_39 AC 92 ms
92,836 KB
testcase_40 AC 70 ms
89,276 KB
testcase_41 AC 38 ms
53,380 KB
testcase_42 AC 68 ms
87,076 KB
testcase_43 AC 37 ms
53,380 KB
testcase_44 AC 37 ms
53,380 KB
testcase_45 AC 44 ms
59,760 KB
testcase_46 AC 37 ms
53,380 KB
testcase_47 AC 38 ms
53,380 KB
testcase_48 AC 37 ms
53,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 尺取り法に近い
# left, rightどこまでいけるかを毎回更新しつつ、left_idx, right_idxを動かしていく

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

start_idx = K-1
left = X[start_idx]-A[start_idx]
right = X[start_idx]+A[start_idx]
left_idx = start_idx
right_idx = start_idx
while left_idx >= 0 and right_idx <= N-1:
    improve = False
    # check left
    while left_idx-1 >= 0 and left <= X[left_idx-1] <= right:
        left = min(left, X[left_idx-1]-A[left_idx-1])
        # left をrightから更新することはないはず、なぜならA幅は同じでrightの方が遠いから
        right = max(right, X[left_idx-1]+A[left_idx-1])
        left_idx -= 1
        improve = True
    
    # check right
    while right_idx+1 <= N-1 and left <= X[right_idx+1] <= right:
        left = min(left, X[right_idx+1]-A[right_idx+1])
        right = max(right, X[right_idx+1]+A[right_idx+1])
        right_idx += 1
        improve = True
        
    #print('left', left, 'right', right, 'left_idx', left_idx, 'right_idx', right_idx)
    
    if improve == False:
        break

ans = right_idx +1 - left_idx 
print(ans)
0