sorry, I make mistake in last post

but I think you can use the simple formula like that
at E27:
=IF(A27<>A26,MAX(D2:D26),E26)

and copy fill down to E28, E29,...