結果

問題 No.2028 Even Choice
ユーザー tamato
提出日時 2022-08-05 21:29:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 112,332 KB
最終ジャッジ日時 2024-09-15 17:39:23
合計ジャッジ時間 5,291 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    from heapq import heappop, heappush
    input = sys.stdin.readline

    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    S = 0
    pq = []
    ans = 0
    for i in range(N - 1, -1, -1):
        a = A[i]
        if i & 1:
            ans = max(ans, a + S)

        heappush(pq, a)
        S += a
        if len(pq) >= K:
            t = heappop(pq)
            S -= t
    print(ans)


if __name__ == '__main__':
    main()
0