結果

問題 No.1007 コイン集め
ユーザー ryo_nryo_n
提出日時 2020-03-06 22:38:54
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 54 ms / 1,500 ms
コード長 651 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 10,952 KB
実行使用メモリ 19,176 KB
最終ジャッジ日時 2023-08-04 12:10:03
合計ジャッジ時間 1,855 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,760 KB
testcase_01 AC 14 ms
7,852 KB
testcase_02 AC 15 ms
7,764 KB
testcase_03 AC 15 ms
7,760 KB
testcase_04 AC 15 ms
7,692 KB
testcase_05 AC 15 ms
7,764 KB
testcase_06 AC 15 ms
7,860 KB
testcase_07 AC 15 ms
7,692 KB
testcase_08 AC 15 ms
7,692 KB
testcase_09 AC 15 ms
7,764 KB
testcase_10 AC 15 ms
7,688 KB
testcase_11 AC 15 ms
7,780 KB
testcase_12 AC 54 ms
19,088 KB
testcase_13 AC 53 ms
18,988 KB
testcase_14 AC 53 ms
19,148 KB
testcase_15 AC 35 ms
10,612 KB
testcase_16 AC 34 ms
10,668 KB
testcase_17 AC 36 ms
10,428 KB
testcase_18 AC 54 ms
19,176 KB
testcase_19 AC 48 ms
19,088 KB
testcase_20 AC 54 ms
19,140 KB
testcase_21 AC 52 ms
19,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, K = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

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

    ans1 = 0
    for a in A[K:]:
        if a < 2:
            ans1 += a
            break
        ans1 += a

    ans2 = 0
    for i in range(K - 2, -1, -1):
        a = A[i]
        if a < 2:
            ans2 += a
            break
        ans2 += a

    if A[K - 1] == 1:
        print(max(ans1, ans2) + A[K - 1])
    else:
        print(ans1 + ans2 + A[K - 1])



    
    
    

if __name__ == '__main__':
    main()

0