結果
| 問題 | No.3683 サーバー代がもったいない! |
| コンテスト | |
| ユーザー |
bolero
|
| 提出日時 | 2026-09-05 13:36:22 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 205 ms / 2,000 ms |
| + 105µs | |
| コード長 | 2,030 bytes |
| 記録 | |
| コンパイル時間 | 4,032 ms |
| コンパイル使用メモリ | 377,708 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-09-05 13:36:38 |
| 合計ジャッジ時間 | 8,817 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#if __has_include(<pch/all.h>)
#include <pch/all.h>
#else
#include <bits/stdc++.h>
#include <atcoder/all>
#endif
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No")
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
#define REVERSE(v) reverse(v.begin(), v.end())
template <typename Container>
void printVector(const Container &v, char delimiter = ' ')
{
for (auto itr = v.begin(); itr != v.end(); itr++)
{
if (itr != v.begin())
{
cout << delimiter;
}
cout << *itr;
}
cout << endl;
}
template <typename Container>
void printlnVector(const Container &v)
{
printVector(v, '\n');
}
void solve()
{
long long N, K;
cin >> N >> K;
vector<vector<long long>> dp(K + 1, vector<long long>(2, LONG_LONG_MIN));
dp[0][0] = 0;
dp[0][1] = 0;
rep(i, N)
{
long long A;
cin >> A;
vector<vector<long long>> next_dp(K + 1, vector<long long>(2, LONG_LONG_MIN));
rep(k, K + 1) rep(pre, 2) rep(next, 2)
{
if (pre && next)
{
continue;
}
if (dp[k][pre] == LONG_LONG_MIN)
{
continue;
}
int next_k = k + next;
if (K < next_k)
{
continue;
}
if (next)
{
next_dp[next_k][next] = max(next_dp[next_k][next], dp[k][pre] + A);
}
else
{
next_dp[next_k][next] = max(next_dp[next_k][next], dp[k][pre]);
}
}
swap(dp, next_dp);
}
long long ans = max(dp[K][0], dp[K][1]);
if (ans == LONG_LONG_MIN)
{
cout << "Impossible" << endl;
}
else
{
cout << ans << endl;
}
}
int main()
{
int T = 1;
// cin >> T;
while (T--)
{
solve();
}
return 0;
}
bolero