結果

問題 No.1007 コイン集め
ユーザー ryo_nryo_n
提出日時 2020-03-06 22:38:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 69 ms / 1,500 ms
コード長 651 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 21,564 KB
最終ジャッジ日時 2024-04-22 09:46:16
合計ジャッジ時間 1,886 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,624 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 28 ms
10,496 KB
testcase_03 AC 29 ms
10,624 KB
testcase_04 AC 26 ms
10,624 KB
testcase_05 AC 26 ms
10,624 KB
testcase_06 AC 27 ms
10,496 KB
testcase_07 AC 26 ms
10,624 KB
testcase_08 AC 27 ms
10,624 KB
testcase_09 AC 28 ms
10,752 KB
testcase_10 AC 28 ms
10,624 KB
testcase_11 AC 26 ms
10,496 KB
testcase_12 AC 67 ms
21,548 KB
testcase_13 AC 65 ms
21,416 KB
testcase_14 AC 69 ms
21,420 KB
testcase_15 AC 47 ms
12,660 KB
testcase_16 AC 46 ms
12,784 KB
testcase_17 AC 47 ms
12,912 KB
testcase_18 AC 67 ms
21,564 KB
testcase_19 AC 58 ms
21,436 KB
testcase_20 AC 66 ms
21,440 KB
testcase_21 AC 64 ms
21,560 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