結果
| 問題 | No.3683 サーバー代がもったいない! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-10 18:44:28 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 285 ms / 2,000 ms |
| + 311µs | |
| コード長 | 1,051 bytes |
| 記録 | |
| コンパイル時間 | 2,370 ms |
| コンパイル使用メモリ | 360,300 KB |
| 実行使用メモリ | 285,952 KB |
| 最終ジャッジ日時 | 2026-09-05 12:33:30 |
| 合計ジャッジ時間 | 9,569 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define all(x) x.begin(), x.end()
const ll INF = 1001001001001001001;
template <typename T>
inline bool chmax(T& a, const T& b) {
return ((a < b) ? (a = b, true) : (false));
}
void solve() {
int N, K;
cin >> N >> K;
vector<int> A(N);
rep(i, 0, N) cin >> A[i];
if (K * 2 - 1 > N) {
cout << "Impossible\n";
return;
}
vector dp(N + 1, vector(K + 1, vector<ll>(2, -INF)));
dp[0][0][0] = 0;
rep(i, 1, N + 1) {
rep(j, 0, K + 1) {
chmax(dp[i][j][0], max(dp[i - 1][j][0], dp[i - 1][j][1]));
if (j == 0) continue;
chmax(dp[i][j][1], dp[i - 1][j - 1][0] + A[i - 1]);
}
}
ll ans = -INF;
chmax(ans, dp[N][K][0]);
chmax(ans, dp[N][K][1]);
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
}