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

## Re:为什么超时啊?

Posted by Kuaitoukid at 2013-07-12 19:52:34 on Problem 2479
In Reply To:为什么超时啊? Posted by:VinerL at 2012-02-07 23:19:12
```> #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: