/ Randle /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 3ms 312.0 KiB
#2 Wrong Answer 3ms 308.0 KiB
#3 Wrong Answer 2ms 328.0 KiB
#4 Wrong Answer 2ms 308.0 KiB
#5 Wrong Answer 5ms 1.301 MiB
#6 Wrong Answer 5ms 1.801 MiB
#7 Wrong Answer 5ms 2.809 MiB
#8 Wrong Answer 6ms 1.676 MiB
#9 Wrong Answer 5ms 1.695 MiB
#10 Wrong Answer 1ms 308.0 KiB

代码

#include<bits/stdc++.h>
const long long maxn=125535;
inline const void read(long long &a)
{
	char c=getchar();long long b=1;a=0;
	while(c<'0'||c>'9'){if(c=='-')b=-1;c=getchar();}
	while(c>='0'&&c<='9')
	{
		a=(a<<1)+(a<<3)+c-'0';
		c=getchar();
	}
	a*=b;
}
long long n,answer=0,a[maxn];
long long sum[maxn],ans[maxn],small=0,ansl=0,ansr=0,res=-INT_MAX;
int main()
{
	ans[0]=sum[0]=0;
	read(n);
	for(long long i=1;i<=n;i++)
	{
		read(a[i]);sum[i]=a[i];
		sum[i]+=sum[i-1];
		ans[i]=sum[i]-ans[small];
		if(ans[i]>res){ansl=small;ansr=i;res=ans[i];}
		if(sum[i]<sum[small])small=i;
	}
	answer=res;
	small=0;res=-INT_MAX;ans[0]=sum[0]=0;
	for(long long i=ansl+1;i<=ansr;i++)a[i]=-INT_MAX;
	for(long long i=1;i<=n;i++)
	{
		sum[i]=a[i];
		sum[i]+=sum[i-1];
		ans[i]=sum[i]-ans[small];
		if(ans[i]>res)res=ans[i];
		if(sum[i]<sum[small])small=i;
	}
	if(res>=0)answer+=res;
	std::cout<<answer;
	return  0;
}

信息

递交者
类型
递交
题目
安全保证 T2
题目数据
下载
语言
C++
递交时间
2017-10-11 20:39:19
评测时间
2017-10-11 20:42:37
评测机
分数
0
总耗时
41ms
峰值内存
2.809 MiB