#include<stdio.h>
#include<string.h>
int max(const int *a, int n){
int i;
int currentMax= 0;
int lastMax= 0;
for(i=0; i<n; ++i){
if(a[i]>= 0){
if(currentMax+ a[i]< a[i]){
currentMax= a[i];
printf("%d\n", currentMax);
lastMax= a[i];
printf("%d\n", lastMax);
}else{
currentMax += a[i];
printf("%d\n", currentMax);
if(currentMax> lastMax){
lastMax= currentMax;
}
}
}else{
currentMax += a[i];
printf("%d\n", currentMax);
}
}
return lastMax;
}
int main(void){
int a[]={1, -2, 3, 10, 11, -9 ,12, 21, -9, 12, -4, 7, 2, -5};
printf("%d\n", max(a, 14));
}