书上错了?

root  •  1年前


include <bits/stdc++.h>

using namespace std; int n,x,f=0,mx,ans=0; bool qf=true; int read(){

int x=0,f=1;
char c=getchar();
while(c<'0'||c>'9'){
	if(c=='-')
		f=-1;
		c=getchar();
}
while(c>='0'&&c<='9'){
	x=x*10+int(c)-int('0');
	c=getchar();
}
return x*f;

} int main(){

cin>>n>>x;
if(x>=0){
	qf=false;
}
else mx=x;
for(int i=1;i<n;++i){
	x=read();
	if(x>=0)qf=false;else mx=max(mx,x);
	f=max(0,f+x);
	ans=max(ans,f);
}
if(qf)cout<<mx;
else
cout<<ans;
return 0;//好习惯; 

}//说实话像我这么良心的人真的没有几个了;


评论:

请先登录,才能进行评论