結果

問題 No.1007 コイン集め
ユーザー brthyyjpbrthyyjp
提出日時 2020-03-06 23:58:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 1,500 ms
コード長 552 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 89,216 KB
最終ジャッジ日時 2024-04-22 10:58:34
合計ジャッジ時間 2,379 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,352 KB
testcase_01 AC 40 ms
51,712 KB
testcase_02 AC 38 ms
51,968 KB
testcase_03 AC 38 ms
51,712 KB
testcase_04 AC 39 ms
52,096 KB
testcase_05 AC 39 ms
52,096 KB
testcase_06 AC 41 ms
52,352 KB
testcase_07 AC 39 ms
52,352 KB
testcase_08 AC 39 ms
52,096 KB
testcase_09 AC 38 ms
52,096 KB
testcase_10 AC 39 ms
52,352 KB
testcase_11 AC 39 ms
52,096 KB
testcase_12 AC 70 ms
87,808 KB
testcase_13 AC 72 ms
88,192 KB
testcase_14 AC 72 ms
87,680 KB
testcase_15 AC 70 ms
83,712 KB
testcase_16 AC 68 ms
83,584 KB
testcase_17 AC 70 ms
83,840 KB
testcase_18 AC 72 ms
89,216 KB
testcase_19 AC 64 ms
82,816 KB
testcase_20 AC 71 ms
89,088 KB
testcase_21 AC 71 ms
88,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
A = list(map(int, input().split()))

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

A = [0] + A + [0]
#print(A)

for i in range(k):
    if A[i] == 0:
        p = i
        q = 0
    elif A[i] == 1:
        p = i
        q = 1

for i in reversed(range(k+1, n+2)):
    if A[i] == 0:
        r = i
        s = 0
    elif A[i] == 1:
        r = i
        s = 1

if A[k] >= 2:
    #print(p, q, r, s)
    ans = sum(A[p:k])+A[k]+sum(A[k+1:r+1])
    print(ans)
else:
    ans = max(sum(A[p:k]), sum(A[k+1:r+1])) + A[k]
    print(ans)
0