#include <iostream> #include <algorithm> #include <cmath> #define maxn 10010 using namespace std; int main() { int n; while(cin>>n) { if(n==0)break; int a[maxn]={0};//使用前缀和,暴力遍历--记得特判一下全为负数的特殊情况 int count = 0; int N[maxn],maxx=-99999; for(int i=1;i<=n;i++) { int num; cin>>num; N[i] = num; if(num<0)count++; a[i] = a[i-1] + num; } int p1,p2; for(int i=1;i<=n;i++) { for(int j=i;j<=n;j++) { int cnt = a[j] - a[i-1]; if(maxx < cnt) { maxx = cnt; p1 = i; p2 = j; } } } if(count == n) { maxx = 0; p1 = 1; p2 = n; } cout<<maxx<<" "<<N[p1]<<" "<<N[p2]<<endl; } } // 64 位输出请用 printf("%lld")