一、题目
二、代码
#include <iostream>
using namespace std;
int main(){
int k;
cin>>k;
int a[k], thisSum = 0, maxSum = -1, tag = 0, firstNum = 0, lastNum = 0;
int temp_first = 0;
for(int i = 0; i < k; i++){
cin>>a[i];
thisSum += a[i];
if(tag == 0){
temp_first = a[i];
tag = 1;
}
if(thisSum > maxSum){
maxSum = thisSum;
firstNum = temp_first;
lastNum = a[i];
}else if(thisSum < 0){
thisSum = 0;
tag = 0;
}
}
if(maxSum < 0){
cout<<0<<" "<<a[0]<<" "<<a[k-1];
}else{
cout<<maxSum<<" "<<firstNum<<" "<<lastNum;
}
}