for input case 1 4 2 10 20 30 40 output is sometimes 99 and sometimes 60.rus this code 5 times and u will see
code :https://ide.codingblocks.com/s/121054
Different output for same input
@shakul There were lots of mistake in your code. Your logic in check function was also giving wrong answers. I have corrected it. Check it now:
You can refer video on book allocation by Prateek bhaiya for clear understanding.