結果

問題 No.2139 K Consecutive Sushi
ユーザー norikamenorikame
提出日時 2022-12-07 09:11:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 1,156 bytes
コンパイル時間 7,123 ms
コンパイル使用メモリ 337,016 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2024-04-21 18:17:47
合計ジャッジ時間 10,102 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 208 ms
14,848 KB
testcase_04 AC 216 ms
14,856 KB
testcase_05 AC 213 ms
14,908 KB
testcase_06 AC 213 ms
14,976 KB
testcase_07 AC 211 ms
14,840 KB
testcase_08 AC 210 ms
14,932 KB
testcase_09 AC 216 ms
14,968 KB
testcase_10 AC 226 ms
14,936 KB
testcase_11 AC 228 ms
14,848 KB
testcase_12 AC 206 ms
14,848 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 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 3 ms
5,376 KB
testcase_23 AC 19 ms
5,376 KB
testcase_24 AC 67 ms
6,528 KB
testcase_25 AC 146 ms
12,928 KB
testcase_26 AC 20 ms
5,376 KB
testcase_27 AC 59 ms
6,400 KB
testcase_28 AC 62 ms
6,400 KB
testcase_29 AC 30 ms
5,376 KB
testcase_30 AC 83 ms
8,192 KB
testcase_31 AC 190 ms
14,288 KB
testcase_32 AC 28 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