Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请教WA在哪里?

Posted by waterine at 2006-10-26 15:31:32 on Problem 2593
#include<stdio.h>
long l[100000],r[100000],a[100000];
void main() {
	long n,i,max;
	while(1) {
		scanf("%d",&n);
		if(n==0) return;
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		l[0]=a[0];
		for(i=1;i<n;i++)
			l[i]=l[i-1]>0?l[i-1]+a[i]:a[i];
		r[n-1]=a[n-1];
		for(i=n-2;i>=0;i--)
			r[i]=r[i+1]>0?r[i+1]+a[i]:a[i];
		for(i=1;i<n;i++)
			l[i]=l[i]>l[i-1]?l[i]:l[i-1];
		for(i=n-2;i>=0;i--) 
			r[i]=r[i]<l[i+1]?r[i]:r[i+1];

		max=l[0]+r[1];
		for(i=1;i<n-1;i++)
			max=max>l[i]+r[i+1]?max:l[i]+r[i+1];

		printf("%ld\n",max);
	}

}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator