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

嗮一下自己的30行代码

Posted by lzqxh at 2011-02-25 23:04:25 on Problem 2479
#include<cstdio>

int max(int x, int y ) {return x>y? x : y; }

int main()
{
	int cas,n; 
	scanf("%d",&cas);
	while ( cas -- )
	{
		scanf("%d",&n);
		int a, b , ans, a_max,k; 
		a = b = a_max = 0;
		ans = -99999999;
		scanf("%d",&k);
		b = a_max = k; 
		a = max(k , 0 );
		for (int i = 1; i<n; i++)
		{
			scanf("%d",&k);
			a = a + k; 
			if ( a < 0 ) a = 0; 
			b = max( b+k , a_max+k );
			ans = max( ans , b);
			a_max = max( a, a_max);
			b = max( b , a_max);
		}
		printf("%d\n",ans);
	}
}

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