結果

問題 No.1007 コイン集め
ユーザー neterukunneterukun
提出日時 2020-03-07 13:21:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 65 ms / 1,500 ms
コード長 507 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 85,240 KB
最終ジャッジ日時 2024-04-22 12:56:50
合計ジャッジ時間 2,152 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,400 KB
testcase_01 AC 38 ms
52,868 KB
testcase_02 AC 38 ms
52,800 KB
testcase_03 AC 38 ms
52,260 KB
testcase_04 AC 38 ms
51,940 KB
testcase_05 AC 37 ms
52,816 KB
testcase_06 AC 38 ms
52,216 KB
testcase_07 AC 38 ms
52,144 KB
testcase_08 AC 38 ms
52,820 KB
testcase_09 AC 39 ms
52,416 KB
testcase_10 AC 37 ms
52,568 KB
testcase_11 AC 38 ms
52,332 KB
testcase_12 AC 65 ms
83,692 KB
testcase_13 AC 65 ms
84,204 KB
testcase_14 AC 65 ms
84,464 KB
testcase_15 AC 56 ms
76,732 KB
testcase_16 AC 55 ms
77,820 KB
testcase_17 AC 55 ms
76,828 KB
testcase_18 AC 65 ms
85,240 KB
testcase_19 AC 65 ms
84,548 KB
testcase_20 AC 65 ms
84,188 KB
testcase_21 AC 64 ms
85,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

l_sum = 0
r_sum = 0
for i in range(k, n):
    if a[i] == 0:
        break
    elif a[i] == 1:
        r_sum += 1
        break
    else:
        r_sum += a[i]

for i in range(k - 2, -1, -1):
    if a[i] == 0:
        break
    elif a[i] == 1:
        l_sum += 1
        break
    else:
        l_sum += a[i]
        
ans = a[k - 1]
if a[k - 1] == 1:
    ans += max(l_sum, r_sum)
if a[k - 1] > 1:
    ans += l_sum + r_sum
print(ans)
0