結果

問題 No.2139 K Consecutive Sushi
ユーザー shobonvipshobonvip
提出日時 2022-12-05 21:16:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 5,014 ms
コンパイル使用メモリ 260,576 KB
実行使用メモリ 10,472 KB
最終ジャッジ日時 2023-08-02 20:06:14
合計ジャッジ時間 9,700 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 101 ms
10,404 KB
testcase_04 AC 101 ms
10,472 KB
testcase_05 AC 101 ms
10,436 KB
testcase_06 AC 101 ms
10,348 KB
testcase_07 AC 101 ms
10,412 KB
testcase_08 AC 93 ms
10,352 KB
testcase_09 AC 94 ms
10,420 KB
testcase_10 AC 98 ms
10,344 KB
testcase_11 AC 98 ms
10,344 KB
testcase_12 AC 91 ms
10,304 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,388 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 33 ms
5,316 KB
testcase_25 AC 68 ms
9,252 KB
testcase_26 AC 11 ms
4,384 KB
testcase_27 AC 28 ms
4,960 KB
testcase_28 AC 30 ms
5,008 KB
testcase_29 AC 15 ms
4,384 KB
testcase_30 AC 37 ms
6,256 KB
testcase_31 AC 88 ms
9,860 KB
testcase_32 AC 16 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef modint998244353 mint;
typedef long long ll;

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

ll e(){
	return (ll)1e18;
}

int main(){
	/* 
	とるものの和の最大値 = 寿司全部 - (とらないものの最小値)
	RMQとかで
	*/
	int n, k; cin >> n >> k;
	vector<ll> a(n);
	for (int i=0; i<n; i++){
		cin >> a[i];
	}
	segtree<ll,op,e> seg(n+1);
	ll ans = 0;
	seg.set(0, 0);
	for (int i=0; i<n; i++){
		//cout << seg.prod(max(0, i+1-k), i+1) + a[i] << endl;
		seg.set(i+1, seg.prod(max(0, i+1-k), i+1) + a[i]);
		ans += a[i];
	}
	cout << ans - seg.prod(max(0, n+1-k), n+1) << endl;
}
0