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

为什么超时啊?

Posted by VinerL at 2012-02-07 23:19:12 on Problem 2479
#include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

int main()
{
	int n;
	int num;
	int i;
	int a[50001];
	int b[50001];
	int c[50001];
	scanf("%d",&n);

	for(int number=0;number<n;number++)
	{
		scanf("%d",&num);
		for( i=0;i<num;i++)
		{
			scanf("%d",&a[i]);
		}

		b[0]=a[0];

		for( i=1;i<num;i++)
		{
			if(b[i-1]>0)
			{
				b[i]=b[i-1]+a[i];
			}
			else
			{
				b[i]=a[i];
			}
		}

		c[num-1]=a[num-1];

		for( i=num-2;i>=0;i--)
		{
			if(c[i+1]>0)
			{
				c[i]=c[i+1]+a[i];
			}
			else
			{
				c[i]=a[i];
			}
		}


		int best=-99999;
		for( i=0;i<num;i++)
		{
			for(int j=i+1;j<num;j++)
			{
				if(b[i]+c[j]>best)
				{
					best=b[i]+c[j];
				}

			}
		}


		printf("%d\n",best);


	}
}

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