結果

問題 No.2139 K Consecutive Sushi
ユーザー kotatsugamekotatsugame
提出日時 2022-12-03 00:54:44
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 509 bytes
コンパイル時間 1,026 ms
使用メモリ 11,292 KB
最終ジャッジ日時 2022-12-03 00:54:49
合計ジャッジ時間 3,884 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
4,904 KB
testcase_01 AC 2 ms
4,904 KB
testcase_02 AC 1 ms
4,900 KB
testcase_03 AC 108 ms
11,164 KB
testcase_04 AC 113 ms
11,208 KB
testcase_05 AC 107 ms
11,292 KB
testcase_06 AC 107 ms
11,200 KB
testcase_07 AC 106 ms
11,200 KB
testcase_08 AC 98 ms
11,164 KB
testcase_09 AC 100 ms
11,228 KB
testcase_10 AC 102 ms
11,220 KB
testcase_11 AC 102 ms
11,164 KB
testcase_12 AC 96 ms
11,160 KB
testcase_13 AC 2 ms
4,900 KB
testcase_14 AC 2 ms
4,900 KB
testcase_15 AC 2 ms
4,900 KB
testcase_16 AC 2 ms
6,948 KB
testcase_17 AC 1 ms
4,900 KB
testcase_18 AC 3 ms
4,900 KB
testcase_19 AC 1 ms
6,948 KB
testcase_20 AC 2 ms
4,904 KB
testcase_21 AC 2 ms
6,952 KB
testcase_22 AC 2 ms
6,948 KB
testcase_23 AC 11 ms
4,904 KB
testcase_24 AC 35 ms
5,544 KB
testcase_25 AC 72 ms
9,888 KB
testcase_26 AC 12 ms
4,900 KB
testcase_27 AC 30 ms
5,216 KB
testcase_28 AC 31 ms
5,208 KB
testcase_29 AC 15 ms
4,900 KB
testcase_30 AC 39 ms
6,588 KB
testcase_31 AC 94 ms
10,672 KB
testcase_32 AC 17 ms
4,904 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<atcoder/segtree>
using namespace std;
long op(long a,long b){return max(a,b);}
long e(){return -1e18;}
int N,K,A[2<<17];
long S[2<<17];
main()
{
	cin>>N>>K;
	K--;
	for(int i=0;i<N;i++)
	{
		cin>>A[i];
		S[i+1]=S[i]+A[i];
	}
	atcoder::segtree<long,op,e>seg(N+2);
	seg.set(0,0L);
	long ans=0;
	for(int i=1;i<=N;i++)
	{
		long now=seg.prod(max(i-K,0),i)+S[i];
		ans=max(ans,now);
		seg.set(i,op(seg.get(i),seg.get(i-1)+S[i-1]-S[i]));
		seg.set(i+1,now-S[i+1]);
	}
	cout<<ans<<endl;
}
0