結果
| 問題 | No.3683 サーバー代がもったいない! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-05 14:33:58 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 2,000 ms |
| + 103µs | |
| コード長 | 973 bytes |
| 記録 | |
| コンパイル時間 | 4,129 ms |
| コンパイル使用メモリ | 376,460 KB |
| 実行使用メモリ | 9,780 KB |
| 最終ジャッジ日時 | 2026-09-05 14:34:14 |
| 合計ジャッジ時間 | 6,943 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (ll i = s; i < (ll)(t); i++)
#define all(x) begin(x), end(x)
template <class T> bool chmin(T& x, T y) {
return x > y ? (x = y, true) : false;
}
template <class T> bool chmax(T& x, T y) {
return x < y ? (x = y, true) : false;
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, 0, n) cin >> a[i];
if ((n + 1) / 2 < k) {
cout << "Impossible\n";
return;
}
vector<ll> dp1(k + 1, -1e18);
vector<ll> dp2(k + 1, -1e18);
dp1[0] = dp2[0] = 0;
for (int x : a) {
auto ndp2 = dp2;
rep(i, 0, k + 1) chmax(ndp2[i], dp1[i]);
vector<ll> ndp1(k + 1, -1e18);
rep(i, 0, k) chmax(ndp1[i + 1], dp2[i] + x);
swap(dp1, ndp1);
swap(dp2, ndp2);
}
cout << max(dp1[k], dp2[k]) << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int t = 1;
// cin >> t;
while (t--) solve();
}