結果

問題 No.3683 サーバー代がもったいない!
コンテスト
ユーザー のらら
提出日時 2026-09-05 16:01:57
言語 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
結果
WA  
実行時間 -
コード長 904 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,042 ms
コンパイル使用メモリ 266,872 KB
実行使用メモリ 9,792 KB
最終ジャッジ日時 2026-09-05 16:02:17
合計ジャッジ時間 7,808 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 25 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//WA
#include <iostream>
#include <algorithm>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
//#define endl "\n";
const long long INF = 1e9;
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));
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        vector<vector<ll>> tmp(K + 1, vector<ll>(2, -INF));
        
        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