結果

問題 No.3683 サーバー代がもったいない!
コンテスト
ユーザー 紫前燈太
提出日時 2026-07-20 22:33:30
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 63 ms / 2,000 ms
+ 877µs
コード長 618 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,953 ms
コンパイル使用メモリ 339,412 KB
実行使用メモリ 46,336 KB
最終ジャッジ日時 2026-09-05 12:44:43
合計ジャッジ時間 5,545 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll inf = (1LL<<35);

int main() {
    int n,k;
    cin >> n >> k;

    vector<vector<ll>>dp (n+1,vector<ll>(k+1,-inf));
    dp[0][0] = 0;

    for(int i=0;i<n;i++){
        ll x;
        cin >> x;

        for(int j=0;j<=k;j++){
            if(dp[i][j] == -inf) continue;

            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);

            if(j != k){
                dp[min(i+2,n)][j+1] = max(dp[min(i+2,n)][j+1], dp[i][j] + x);
            }
        }
    }

    if(dp[n][k] == -inf) cout << "Impossible" << endl;
    else cout << dp[n][k] << endl;
}
0