code :https://ide.codingblocks.com/#/s/18024
ques link:https://hack.codingblocks.com/contests/c/452/1259
I am getting wrong answer.
Tell me mistake in code
Maximum Array Sum
shrey ur code is fine but not gave right output for some case like
1
6
-2 -8 -5 -1 -7 1
i have solved using dp check this
https://ide.codingblocks.com/#/s/18033
if any problem reply
Happy Coding!
Heyy ! as you are checking wheather current sum is negative or not , suppose your array contains only negative nos then you should print the max sum (which obviously a negative no) but as you are doing this way ,in every iteration current sum will be negative and before assigning current sum to max sum you are assigning it to zero , so check for its maximum first and then check wheather curr sum is negative or not . Other part of ur code is pretty fine .
https://ide.codingblocks.com/#/s/18034
It is giving correct output for you specified testcase. Answer should be one
I dealt separately if all numbers are negative. i am still not getting any error in my code?
shrey
1
8
2 -2 -1 5 -3 6 -8 0
for this test case ur output is showing 6 but ans is 8 ,Actually i think that the sort u use is the problem