結果
| 問題 | No.3683 サーバー代がもったいない! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-05 13:45:12 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 309 ms / 2,000 ms |
| + 147µs | |
| コード長 | 724 bytes |
| 記録 | |
| コンパイル時間 | 2,583 ms |
| コンパイル使用メモリ | 369,708 KB |
| 実行使用メモリ | 285,596 KB |
| 最終ジャッジ日時 | 2026-09-05 13:49:20 |
| 合計ジャッジ時間 | 9,815 ms |
|
ジャッジサーバーID (参考情報) |
judge5_1 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector dp(N + 1, vector(K + 1, vector<ll>(2, LLONG_MIN)));
dp[0][0][0] = 0;
auto chmax = [&](ll& a, ll b) { a = max(a, b); };
for(int i=0; i<N; i++) {
ll A; cin >> A;
dp[i+1] = dp[i];
for(int k=0; k<=K; k++) chmax(dp[i+1][k][0], dp[i][k][1]);
for(int k=0; k<K; k++) {
if(dp[i][k][0] == LLONG_MIN) continue;
chmax(dp[i+1][k+1][1], dp[i][k][0] + A);
}
}
ll ans = max(dp[N][K][0], dp[N][K][1]);
cout << (ans == LLONG_MIN ? "Impossible" : to_string(ans)) << endl;
}