#include <iostream>
#include <limits.h>
using namespace std;
int maxSubArray(int* nums, int numsSize) {
int curSum, maxSum = INT_MIN;
curSum = 0;
for(int i = 0; i < numsSize; i++){
curSum = curSum + nums[i];
if(curSum > maxSum){
maxSum = curSum;
}
if(curSum < 0){
curSum = 0;
}
}
return maxSum;
}
int main() {
int myints[] = {10, 0, 30, 0, -50, 60, -90, 80};
cout << maxSubArray(myints, 8) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bGltaXRzLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWF4U3ViQXJyYXkoaW50KiBudW1zLCBpbnQgbnVtc1NpemUpIHsKICAgIGludCBjdXJTdW0sIG1heFN1bSA9IElOVF9NSU47CiAgICBjdXJTdW0gPSAwOwogICAgZm9yKGludCBpID0gMDsgaSA8IG51bXNTaXplOyBpKyspewogICAgICAgIGN1clN1bSA9IGN1clN1bSArIG51bXNbaV07CiAgICAgICAgaWYoY3VyU3VtID4gbWF4U3VtKXsKICAgICAgICAgICAgbWF4U3VtID0gY3VyU3VtOwogICAgICAgIH0KICAgICAgICBpZihjdXJTdW0gPCAwKXsKICAgICAgICAgICAgY3VyU3VtID0gMDsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gbWF4U3VtOwp9CgppbnQgbWFpbigpIHsKCWludCBteWludHNbXSA9IHsxMCwgMCwgMzAsIDAsIC01MCwgNjAsIC05MCwgODB9OwoJY291dCA8PCBtYXhTdWJBcnJheShteWludHMsIDgpIDw8IGVuZGw7CglyZXR1cm4gMDsKfQ==