結果
| 問題 | No.3683 サーバー代がもったいない! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-06 23:34:17 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 281 ms / 2,000 ms |
| + 256µs | |
| コード長 | 753 bytes |
| 記録 | |
| コンパイル時間 | 1,076 ms |
| コンパイル使用メモリ | 175,276 KB |
| 実行使用メモリ | 285,824 KB |
| 最終ジャッジ日時 | 2026-09-06 23:34:26 |
| 合計ジャッジ時間 | 7,932 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <algorithm>
#include <ios>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) cin >> A[i];
ll INF = 1ll << 60;
vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(K + 1, vector<ll>(2, -INF)));
dp[0][0][0] = 0;
for (int i = 0; i < N; i++) for (int j = 0; j <= K; j++) {
dp[i + 1][j][0] = max(dp[i][j][0], dp[i][j][1]);
if (j < K && dp[i][j][0] != -INF) {
dp[i + 1][j + 1][1] = dp[i][j][0] + A[i];
}
}
ll ans = max(dp[N][K][0], dp[N][K][1]);
if (ans == -INF) {
cout << "Impossible\n";
} else {
cout << ans << '\n';
}
}