結果

問題 No.1007 コイン集め
コンテスト
ユーザー H20
提出日時 2021-01-27 09:55:33
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 80 ms / 1,500 ms
+ 184µs
コード長 436 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 237 ms
コンパイル使用メモリ 95,468 KB
実行使用メモリ 99,584 KB
最終ジャッジ日時 2026-07-28 23:00:16
合計ジャッジ時間 3,479 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N,K = map(int, input().split())
A = list(map(int, input().split())) 
r=K-1
l=K-1
if A[K-1]>=2:
    while l>=1 and A[l]>=2 and A[l-1]>=1:
        l-=1
    while r<N-1 and A[r]>=2 and A[r+1]>=1:
        r+=1
    print(sum(A[l:r+1]))
elif A[K-1]==0:
    print(0)
else:
    A[K-1]+=1
    while l>=1 and A[l]>=2 and A[l-1]>=1:
        l-=1
    while r<N-1 and A[r]>=2 and A[r+1]>=1:
        r+=1
    print(max(sum(A[l:K]),sum(A[K-1:r+1]))-1)
0