結果

問題 No.3683 サーバー代がもったいない!
コンテスト
ユーザー Takumi1226
提出日時 2026-09-05 13:58:59
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 174 ms / 2,000 ms
+ 822µs
コード長 731 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 228 ms
コンパイル使用メモリ 95,816 KB
実行使用メモリ 101,632 KB
最終ジャッジ日時 2026-09-05 13:59:51
合計ジャッジ時間 7,147 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import itertools
from copy import deepcopy
from functools import cache
import sys
sys.setrecursionlimit(10 ** 9)
import math
from collections import Counter, deque
input = lambda: sys.stdin.readline().rstrip()
mod = 998244353

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

now_dp = [[-math.inf, -math.inf] for _ in range(k + 1)]
now_dp[0][1] = 0

# print(dp)

for i in range(n):
    for j in range(k, 0, -1):
        if now_dp[j][0] != -math.inf:
            now_dp[j][1] = max(now_dp[j][1], now_dp[j][0])
        if now_dp[j - 1][1] != -math.inf:
            now_dp[j][0] = now_dp[j - 1][1] + a[i]
# print(next_dp)

if max(now_dp[-1]) == -math.inf:
    print("Impossible")
else:
    print(max(now_dp[-1]))
0