結果
問題 | No.871 かえるのうた |
ユーザー |
![]() |
提出日時 | 2023-02-27 16:14:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 124 ms / 2,000 ms |
コード長 | 970 bytes |
コンパイル時間 | 222 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 99,712 KB |
最終ジャッジ日時 | 2024-11-30 11:12:21 |
合計ジャッジ時間 | 4,576 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 49 |
ソースコード
# 公式解説も同じ考え、区間を更新する、左端と右端# 公式解説のやり方だと左も右も一歩ずつ進んでループがない# 左端限界値、右端限界値を管理N, K = map(int, input().split())INF = 10**20X = [-INF]+list(map(int, input().split()))+[INF]A = [0]+list(map(int, input().split()))+[0]left_idx = Kright_idx = Kleft_min = X[K]-A[K]right_max = X[K]+A[K]while True:update = Falsewhile left_idx-1 >= 1 and left_min <= X[left_idx-1]:update = Trueleft_idx -= 1left_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 and right_max >= X[right_idx+1]:update = Trueright_idx += 1left_min = min(left_min, X[right_idx]-A[right_idx])right_max = max(right_max, X[right_idx]+A[right_idx])if update == False:breakans = right_idx + 1 - left_idxprint(ans)