题目:
http://acm.hdu.edu.cn/showproblem.php?pid=1003
#include <stdio.h>
#include<algorithm>
#define MAX 100005
using namespace std;
int arry[MAX];
int main(){
int t,n,i,co=1;
scanf("%d",&t);
while(t--){
if(co!=1)
printf("\n");
scanf("%d",&n);
intdp[MAX] = {0};
intstart,end,cont=-1;
longmax;
scanf("%d",&arry[0]);
max=dp[0] =arry[0];
for(i =1;i < n;i++){
scanf("%d",&arry[i]);
if(dp[i-1] >= 0){
dp[i] = dp[i-1] + arry[i];
cont++;
}
else{
dp[i] = arry[i];
cont = -1;
}
if(dp[i]>max){
max = dp[i];
start = i-cont;
end = i+1;
}
if(dp[0]==max){//这一步WA了好几次没考虑全面
start = 1;
end = 1;
}
}
printf("Case%d:\n%ld %d %d\n",co++,max,start,end);
}
return 0;
}