Maxmum subarray sum

there is run error in the first 2 cases and right answer in last two cases. please check the code: