結果
| 問題 | No.3683 サーバー代がもったいない! |
| コンテスト | |
| ユーザー |
dokukuma
|
| 提出日時 | 2026-09-05 13:39:51 |
| 言語 | PyPy3 (7.3.23) |
| 結果 |
AC
|
| 実行時間 | 289 ms / 2,000 ms |
| + 269µs | |
| コード長 | 1,074 bytes |
| 記録 | |
| コンパイル時間 | 226 ms |
| コンパイル使用メモリ | 96,076 KB |
| 実行使用メモリ | 104,532 KB |
| 最終ジャッジ日時 | 2026-09-05 13:41:08 |
| 合計ジャッジ時間 | 8,805 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
import sys, time, random, heapq, math, itertools, copy
from collections import deque, Counter, defaultdict
#from sortedcontainers import SortedSet, SortedList
from bisect import bisect, bisect_left, bisect_right
import heapq as hq
from functools import cache, cmp_to_key
def debug(*x):print('debug:',*x, file=sys.stderr)
sys.setrecursionlimit(300000)
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 61 - 1
mod = 998244353
dir = [(0, 1), (0, -1), (1, 0), (-1, 0)]
N, K = mi()
A = li()
if N < 2 * K - 1:
print("Impossible")
exit()
dp = [[-inf, -inf] for _ in range(K+1)]
dp[0][0] = 0
for i in range(N):
next_dp = [[-inf, -inf] for _ in range(K+1)]
for j in range(K+1):
if j + 1 < K+1 and dp[j][0] != -inf:
# 選ぶ
next_dp[j+1][1] = max(next_dp[j+1][1], dp[j][0] + A[i])
#選ばない
next_dp[j][0] = max(next_dp[j][0], dp[j][0], dp[j][1])
dp = next_dp
debug(dp)
ans = max(dp[-1][0], dp[-1][1])
print(ans)
dokukuma