結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,812 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 239 ms
14,792 KB
testcase_04 AC 247 ms
14,900 KB
testcase_05 AC 235 ms
14,860 KB
testcase_06 AC 227 ms
14,988 KB
testcase_07 AC 240 ms
14,784 KB
testcase_08 AC 236 ms
14,928 KB
testcase_09 AC 238 ms
14,856 KB
testcase_10 AC 240 ms
14,856 KB
testcase_11 AC 236 ms
15,008 KB
testcase_12 AC 227 ms
14,796 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 3 ms
6,940 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 4 ms
6,940 KB
testcase_23 AC 22 ms
6,944 KB
testcase_24 AC 74 ms
6,944 KB
testcase_25 AC 162 ms
13,060 KB
testcase_26 AC 23 ms
6,944 KB
testcase_27 AC 63 ms
6,940 KB
testcase_28 AC 64 ms
6,940 KB
testcase_29 AC 30 ms
6,944 KB
testcase_30 AC 86 ms
8,320 KB
testcase_31 AC 217 ms
14,284 KB
testcase_32 AC 34 ms
6,940 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