結果

問題 No.1007 コイン集め
ユーザー H20
提出日時 2021-01-27 09:55:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 1,500 ms
コード長 436 bytes
コンパイル時間 334 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 85,628 KB
最終ジャッジ日時 2024-06-24 08:43:09
合計ジャッジ時間 2,619 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

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