結果

問題 No.2139 K Consecutive Sushi
ユーザー 👑 AngrySadEightAngrySadEight
提出日時 2022-11-27 00:12:06
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 769 bytes
コンパイル時間 3,160 ms
コンパイル使用メモリ 160,728 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-11-27 19:45:49
合計ジャッジ時間 5,970 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;

ll op(ll a, ll b){
    return min(a, b);
}

ll e(){
    return 100000000000000007;
}

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++){
        cin >> A[i];
    }

    ll sum = 0;
    for (ll i = 0; i < N; i++) sum += A[i];

    segtree<ll, op, e> dp(N + 1);
    dp.set(0, 0);

    for (ll i = 1; i <= N; i++){
        ll min_val;
        if (i <= K){
            min_val = dp.prod(0, i);
        }
        else{
            min_val = dp.prod(i - K, i);
        }
        ll next_val = min(min_val + A[i - 1], dp.get(i));
        dp.set(i, next_val);
    }
    cout << sum - dp.prod(N - K + 1, N + 1) << endl;
}
0