結果

問題 No.2139 K Consecutive Sushi
ユーザー V_Melville
提出日時 2022-12-19 22:16:06
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 70 ms / 2,000 ms
+ 730µs
コード長 662 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,642 ms
コンパイル使用メモリ 378,732 KB
実行使用メモリ 9,864 KB
最終ジャッジ日時 2026-10-20 07:50:04
合計ジャッジ時間 9,266 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;

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

ll e() { return 1e18; }

int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    
    ll ans = 0;
    rep(i, n) ans += a[i];
    
    segtree<ll, op, e> t(n);
    rep(i, k) t.set(i, a[i]);
    for (int i = k; i < n; ++i) {
        ll now = t.prod(i-k, i)+a[i];
        t.set(i, now);
    }
    ans -= t.prod(n-k, n);
    
    cout << ans << '\n';
    
    return 0;
}
0