結果
問題 | No.2139 K Consecutive Sushi |
ユーザー |
|
提出日時 | 2022-12-19 22:16:06 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 101 ms / 2,000 ms |
コード長 | 662 bytes |
コンパイル時間 | 5,420 ms |
コンパイル使用メモリ | 309,404 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-11-27 19:54:46 |
合計ジャッジ時間 | 6,893 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
#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; }