Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
一些数据通过了,不知为何就是WA...TAT.. 请教大牛们了。。俺的代码。 #include<iostream> #include<stdio.h> using namespace std; //============================================================= int p[100005]; #define M -1001; int maxsum=M; int sum1[100005];int sum2[100005]; int main() { long long n; int max=M; while(cin>>n&&n) { memset(p,0,sizeof(p)); memset(sum1,0,sizeof(sum1)); memset(sum2,0,sizeof(sum2)); scanf("%d",&p[0]); sum1[0]=p[0]; for(int i=1;i<n;++i) { scanf("%d",&p[i]); if(sum1[i-1]>0) { sum1[i]=sum1[i-1]+p[i]; } else { sum1[i]=p[i]; } //if(sum1[i]>max)max=sum1[i]; } int m=M; sum2[n-1]=p[n-1]; for(int i=n-1;i>=1;--i) { if(sum2[i]>0) { sum2[i-1]=sum2[i]+p[i-1]; } else { sum2[i-1]=p[i-1]; } if(sum2[i]>m)m=sum2[i]; if(m+sum1[i-1]>maxsum) { maxsum=m+sum1[i-1]; } } printf("%d\n",maxsum); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator