結果
| 問題 | No.3683 サーバー代がもったいない! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-05 13:06:11 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0) |
| 結果 |
AC
|
| 実行時間 | 156 ms / 2,000 ms |
| + 790µs | |
| コード長 | 1,332 bytes |
| 記録 | |
| コンパイル時間 | 2,851 ms |
| コンパイル使用メモリ | 385,900 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2026-09-05 13:06:58 |
| 合計ジャッジ時間 | 7,542 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
#pragma GCC optimize ("O3,inline,omit-frame-pointer,no-asynchronous-unwind-tables,fast-math")
#include <bits/stdc++.h>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define rep(i, a, n) for(ll i = a; i < n; i++)
#define rrep(i, a, n) for(ll i = a; i >= n; i--)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
constexpr int IINF = 1001001001;
constexpr ll INF = 1LL<<60;
#define all(x) (x).begin(), (x).end()
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
int main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n, k; cin >> n >> k;
vector<ll> a(n);
rep(i,0,n) cin >> a[i];
vector<vector<ll>> dp(k+1,vector<ll>(2,-INF));
dp[0][0] = 0;
rep(i,0,n){
vector<vector<ll>> ndp(k+1,vector<ll>(2,-INF));
rep(j,0,k+1){
if(dp[j][0] != -INF){
chmax(ndp[j][0],dp[j][0]);
if(j < k) chmax(ndp[j+1][1],dp[j][0]+a[i]);
}
chmax(ndp[j][0],dp[j][1]);
}
swap(dp,ndp);
}
ll ans = max(dp[k][0],dp[k][1]);
if(ans == -INF) cout << "Impossible" << endl;
else cout << ans << endl;
return 0;
}