bestEndingHere = max(a[i], bestEndingHere + a[i]); bestSoFar tracks the global maximum. Watch the recurrence extend or restart at each index.
junior.md and professional.md for the proof that a negative running prefix is never worth carrying forward.