https://www.patest.cn/contests/pat-a-practise/1007
#include <cstdio>
#include <climits>
int main()
{
int a[10000],n,maxSum=INT_MIN,maxBegin,maxEnd=0,sum=INT_MIN,begin = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (sum < 0) {
sum = a[i];
begin = i;
}
else {
sum += a[i];
}
if (maxSum < sum) {
maxSum = sum;
maxBegin = begin;
maxEnd = i;
}
}
if (maxSum < 0) {
printf("0 %d %d\n", a[0], a[n - 1]);
}
else {
printf("%d %d %d\n", maxSum, a[maxBegin], a[maxEnd]);
}
return 0;
}