求最大连续子序列, 模板题。。还好自己还有印象。敲上就A了
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cmath>
#include <iomanip>
typedef long long LL;
typedef unsigned long long LLU;
const double PI=acos(-1.0);
using namespace std;
#define MAXN 10000+10
int main (){
int n;
while(scanf("%d",&n) != EOF && n){
int a[MAXN];
for(int i = 0; i < n; i++)
scanf("%d",&a[i]);
int sum = 0;
int x = a[0];
int y = a[0];
int M = -1;
int xx = a[0];
for(int i = 0; i < n; i++){
sum += a[i];
if(sum > M){
x = xx;
y = a[i];
M = sum;
}
if(sum < 0){
sum = 0;
xx = a[i+1];
}
}
if(M < 0)
printf("%d %d %d\n",0,a[0],a[n-1]);
else
printf("%d %d %d\n",M,x,y);
}
return 0;
}