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 |
为什么超时啊?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator