結果

問題 No.2139 K Consecutive Sushi
ユーザー norikamenorikame
提出日時 2022-12-07 09:18:54
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 2,000 ms
コード長 1,156 bytes
コンパイル時間 6,555 ms
コンパイル使用メモリ 336,400 KB
実行使用メモリ 15,072 KB
最終ジャッジ日時 2024-04-21 18:23:10
合計ジャッジ時間 11,226 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 242 ms
14,976 KB
testcase_04 AC 250 ms
14,848 KB
testcase_05 AC 243 ms
14,976 KB
testcase_06 AC 239 ms
14,972 KB
testcase_07 AC 237 ms
14,848 KB
testcase_08 AC 233 ms
15,072 KB
testcase_09 AC 244 ms
14,976 KB
testcase_10 AC 252 ms
14,848 KB
testcase_11 AC 246 ms
14,840 KB
testcase_12 AC 232 ms
14,928 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
testcase_23 AC 22 ms
5,376 KB
testcase_24 AC 75 ms
6,784 KB
testcase_25 AC 166 ms
13,056 KB
testcase_26 AC 23 ms
5,376 KB
testcase_27 AC 63 ms
6,400 KB
testcase_28 AC 65 ms
6,528 KB
testcase_29 AC 31 ms
5,376 KB
testcase_30 AC 85 ms
8,192 KB
testcase_31 AC 216 ms
14,208 KB
testcase_32 AC 34 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

const ll LINF = (ll)(1e18);

ll op(ll a, ll b) { return max(a, b); }
ll e() { return -LINF; }
ll mapping(ll f, ll x) { return x + f; }
ll composition(ll f, ll g) { return f + g; }
ll id() { return 0LL; }

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> sum(n+1);
	rep(i, n) sum[i+1] = sum[i] + a[i];
	vector<ll> dp(n+1);
	lazy_segtree<ll, op, e, ll, mapping, composition, id> st(n+1);
	ll res = -LINF;
	dp[0] = 0;
	res = max(res, dp[0]);
	st.set(0, dp[0]);
	rep(i, n) {
		int li0 = max(0, (i+1)-(k-1)), li1 = max(0, (i+1)-k);
		dp[i+1] = st.prod(li1, i+1);
		res = max(res, st.prod(li0,i+1)+a[i]);
		st.apply(li0, i+1, a[i]);
		st.set(i+1, dp[i+1]);
	}
	res = max(res, dp[n]);
	cout << res << endl;
	return 0;
}
0