結果

問題 No.1007 コイン集め
ユーザー TsuboTsubo
提出日時 2020-03-09 15:53:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 79 ms / 1,500 ms
コード長 660 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 21,676 KB
最終ジャッジ日時 2024-04-25 15:26:04
合計ジャッジ時間 2,037 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,624 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 30 ms
10,752 KB
testcase_05 AC 29 ms
10,880 KB
testcase_06 AC 29 ms
10,624 KB
testcase_07 AC 30 ms
10,624 KB
testcase_08 AC 31 ms
10,624 KB
testcase_09 AC 30 ms
10,752 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 29 ms
10,752 KB
testcase_12 AC 75 ms
21,536 KB
testcase_13 AC 78 ms
21,536 KB
testcase_14 AC 75 ms
21,664 KB
testcase_15 AC 50 ms
13,028 KB
testcase_16 AC 51 ms
12,904 KB
testcase_17 AC 49 ms
12,900 KB
testcase_18 AC 78 ms
21,676 KB
testcase_19 AC 64 ms
21,676 KB
testcase_20 AC 79 ms
21,552 KB
testcase_21 AC 71 ms
21,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N,K=map(int,readline().split())
    A=list(map(int,readline().split()))

    if A[K-1]==0:
        print(0)

    elif A[K-1]>=1:
        left=0
        right=0
        now=K-1
        while now>0:
            now-=1
            left+=A[now]
            if A[now]<=1:
                break
        now=K-1
        while now<N-1:
            now+=1
            right+=A[now]
            if A[now]<=1:
                break
        
        if A[K-1]==1:
            print(A[K-1]+max(left,right))
        else:
            print(A[K-1]+left+right)


if __name__=="__main__":
    main()
0