应该是和题解差不多的想法,为什么错了呢
查看原帖
应该是和题解差不多的想法,为什么错了呢
119643
潜水的蒟蒻楼主2020/6/13 21:18
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
long long a[1000005],ans,maxx;
int main()//¿¾main°ü
{
 	//ios::sync_with_stdio(false);
	int n,k;cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=k+1;i++)ans+=a[i];
	//cout<<"when i was:1 the ans was:"<<ans<<" the maxx was:0"<<endl;
	for(int i=2;i<=n-k;i++)
	{
		maxx-=a[i-1];
		maxx+=a[i+k];
		ans=max(ans,maxx);
		//cout<<"when i was:"<<i<<"  the ans was:"<<ans<<" the maxx was:"<<maxx<<endl;
	}
	cout<<ans;
	return 0;
}

先算第一个区间,然后吞一个数吐一个数,但是比如k为0时就错.
那么题解中为什么就可以是对的....

2020/6/13 21:18
加载中...