結果

問題 No.1007 コイン集め
ユーザー Azumabashi
提出日時 2020-04-24 13:32:20
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 922 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 21,816 KB
最終ジャッジ日時 2024-10-15 01:49:29
合計ジャッジ時間 2,773 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 WA * 7 RE * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left


def main():
    length, start = map(int, input().split())
    start -= 1
    coins = [int(x) for x in input().split()]
    only_1_coin_index = []
    for i in range(length):
        if i == start:
            continue
        if coins[i] == 1:
            only_1_coin_index.append(i)
    answer = 0
    if coins[start] > 1:
        nearest_1_coin = bisect_left(only_1_coin_index, start)
        if nearest_1_coin == 0:
            answer = max(sum(coins[:start + 1]), sum(coins[start: only_1_coin_index[0] + 1]))
        elif nearest_1_coin == len(only_1_coin_index):
            answer = max(sum(coins[only_1_coin_index[0]:start + 1]), sum(coins[start:]))
        else:
            left = only_1_coin_index[nearest_1_coin - 1]
            right = only_1_coin_index[nearest_1_coin]
            answer = sum(coins[left:right + 1])
    print(answer)


if __name__ == '__main__':
    main()

0