結果

問題 No.3683 サーバー代がもったいない!
コンテスト
ユーザー Kato, H.
提出日時 2026-09-05 15:36:07
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 543 ms / 2,000 ms
+ 917µs
コード長 719 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 251 ms
コンパイル使用メモリ 96,072 KB
実行使用メモリ 97,920 KB
最終ジャッジ日時 2026-09-05 15:36:28
合計ジャッジ時間 11,259 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# -*- coding: utf-8 -*-


def main():
    import sys

    input = sys.stdin.readline

    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    inf = 10**18
    dp = [[-inf for _ in range(2)] for _ in range(k + 1)]
    dp[0][0] = 0

    for i, ai in enumerate(a):
        ndp = [[-inf for _ in range(2)] for _ in range(k + 1)]

        for j in range(k + 1):
            ndp[j][0] = max(ndp[j][0], dp[j][0], dp[j][1])

            nj = j + 1

            if nj > k:
                continue

            ndp[nj][1] = max(ndp[nj][1], dp[j][0] + ai)

        dp = ndp

    ans = max(dp[k])

    if ans < -(10**15):
        ans = "Impossible"

    print(ans)


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