結果

問題 No.1007 コイン集め
コンテスト
ユーザー H20
提出日時 2021-01-27 09:55:33
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 44 ms / 1,500 ms
コード長 436 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 122 ms
コンパイル使用メモリ 85,264 KB
実行使用メモリ 86,912 KB
最終ジャッジ日時 2026-03-10 09:25:56
合計ジャッジ時間 1,893 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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