题目链接

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+5;
int arr[maxn];
int dp[maxn];
int pre[maxn];
int main(){
	int n; 
	while(cin>>n){
		if(n==0) break;
		for(int i=1;i<=n;i++){
			cin>>arr[i];
		}
		memset(dp,0,sizeof(dp));
		pre[1] = arr[1];
		dp[1] = arr[1];
		int Max=0, ans;
		for(int i=2;i<=n;i++){
			if(dp[i-1]+arr[i] > arr[i]){
				dp[i] = dp[i-1]+arr[i];
				pre[i] = pre[i-1];
			}else{
				dp[i] = arr[i];
				pre[i] = arr[i];
			}
			
		}
		for(int i=1;i<=n;i++){
			if(dp[i] > Max){
				Max = dp[i];
				ans = i;
			}
		}
		if(Max==0){
			cout<<"0 "<<arr[1]<<" "<<arr[n]<<endl;
		}else{
			cout<<Max<<" "<<pre[ans]<<" "<<arr[ans]<<endl;
		}
	} 
	
	return 0;
}