結果

問題 No.2139 K Consecutive Sushi
ユーザー kotatsugamekotatsugame
提出日時 2022-12-03 00:54:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 509 bytes
コンパイル時間 757 ms
コンパイル使用メモリ 78,952 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-18 10:01:06
合計ジャッジ時間 3,493 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 115 ms
11,292 KB
testcase_04 AC 115 ms
11,324 KB
testcase_05 AC 112 ms
11,696 KB
testcase_06 AC 114 ms
11,308 KB
testcase_07 AC 113 ms
11,756 KB
testcase_08 AC 104 ms
11,776 KB
testcase_09 AC 107 ms
11,660 KB
testcase_10 AC 108 ms
11,212 KB
testcase_11 AC 111 ms
11,704 KB
testcase_12 AC 105 ms
11,424 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 3 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 12 ms
6,940 KB
testcase_24 AC 38 ms
6,940 KB
testcase_25 AC 77 ms
11,236 KB
testcase_26 AC 13 ms
6,940 KB
testcase_27 AC 32 ms
6,940 KB
testcase_28 AC 33 ms
7,116 KB
testcase_29 AC 17 ms
6,940 KB
testcase_30 AC 41 ms
8,396 KB
testcase_31 AC 100 ms
11,032 KB
testcase_32 AC 18 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-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