結果

問題 No.3683 サーバー代がもったいない!
コンテスト
ユーザー のらら
提出日時 2026-09-05 14:00:45
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 181 ms / 2,000 ms
+ 96µs
コード長 923 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,802 ms
コンパイル使用メモリ 266,316 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 14:01:39
合計ジャッジ時間 8,137 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
//#define endl "\n";
const long long INF = 1000000000000000000;
int main(){
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<vector<ll>> dp(K + 1, vector<ll>(2, -INF * 2));
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        vector<vector<ll>> tmp(K + 1, vector<ll>(2, -INF * 2));
        
        for(int j = 0; j <= K; j++){
            //選ぶ
            if(j + 1 <= K) tmp[j + 1][1] = max(tmp[j + 1][1], dp[j][0] + A[i]);
            //選ばない
            tmp[j][0] = max(tmp[j][0], dp[j][0]);
            tmp[j][0] = max(tmp[j][0], dp[j][1]);
        }
        swap(dp, tmp);
    }
    ll ans = max(dp[K][0], dp[K][1]);
    if(ans < -INF) cout << "Impossible" << endl;
    else cout << ans << endl;
    return 0;
}
0