second version of maxSumPath, better performance