結果

問題 No.871 かえるのうた
ユーザー FromBooskaFromBooska
提出日時 2024-03-12 13:27:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,189 bytes
コンパイル時間 315 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 98,500 KB
最終ジャッジ日時 2024-03-12 13:27:11
合計ジャッジ時間 7,025 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 36 ms
53,456 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 36 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 39 ms
59,444 KB
testcase_09 AC 41 ms
59,444 KB
testcase_10 AC 41 ms
59,456 KB
testcase_11 AC 39 ms
59,444 KB
testcase_12 AC 45 ms
67,744 KB
testcase_13 AC 42 ms
61,556 KB
testcase_14 AC 90 ms
93,036 KB
testcase_15 AC 88 ms
93,080 KB
testcase_16 AC 102 ms
94,064 KB
testcase_17 AC 86 ms
94,868 KB
testcase_18 AC 46 ms
68,328 KB
testcase_19 AC 96 ms
93,552 KB
testcase_20 AC 49 ms
66,620 KB
testcase_21 AC 72 ms
85,300 KB
testcase_22 AC 35 ms
53,460 KB
testcase_23 AC 35 ms
53,460 KB
testcase_24 AC 35 ms
53,460 KB
testcase_25 AC 44 ms
62,096 KB
testcase_26 AC 44 ms
64,116 KB
testcase_27 AC 42 ms
66,184 KB
testcase_28 AC 36 ms
53,460 KB
testcase_29 AC 62 ms
87,116 KB
testcase_30 AC 84 ms
97,668 KB
testcase_31 AC 39 ms
59,444 KB
testcase_32 AC 78 ms
94,564 KB
testcase_33 AC 90 ms
96,104 KB
testcase_34 AC 46 ms
70,012 KB
testcase_35 AC 65 ms
88,864 KB
testcase_36 AC 79 ms
98,500 KB
testcase_37 AC 67 ms
84,800 KB
testcase_38 AC 93 ms
94,984 KB
testcase_39 AC 89 ms
93,172 KB
testcase_40 AC 70 ms
89,540 KB
testcase_41 AC 35 ms
53,460 KB
testcase_42 AC 63 ms
87,348 KB
testcase_43 AC 35 ms
53,460 KB
testcase_44 AC 36 ms
53,460 KB
testcase_45 AC 43 ms
59,956 KB
testcase_46 AC 36 ms
53,460 KB
testcase_47 AC 36 ms
53,460 KB
testcase_48 AC 36 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# しゃくとり法に近い、two pointer、left_min, right_max, left_idx, right_idxを管理してwhile使う

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

K -= 1
left_idx = K
right_idx = K
left_min = X[K]-A[K]
right_max = X[K]+A[K]
#print('left_idx', left_idx, 'right_idx', right_idx, 'left_min', left_min, 'right_max', right_max)
while left_idx>0 or right_idx<N-1:
    improve = False
    
    while left_idx-1>=0 and left_min <= X[left_idx-1] <= right_max:
        improve = True
        left_idx -= 1
        left_min = min(left_min, X[left_idx]-A[left_idx])
        right_max = max(right_max, X[left_idx]+A[left_idx])

    while right_idx+1<=N-1 and left_min <= X[right_idx+1] <= right_max:
        improve = True
        right_idx += 1
        left_min = min(left_min, X[right_idx]-A[right_idx])
        right_max = max(right_max, X[right_idx]+A[right_idx])      

    #print('left_idx', left_idx, 'right_idx', right_idx, 'left_min', left_min, 'right_max', right_max, 'improve', improve)
    if improve == False:
        break

#print('left_idx', left_idx, 'right_idx', right_idx)
ans = right_idx+1-left_idx
print(ans)
0