In E10, copied down, use this:

=C10-LOOKUP(10^300,$C$2:$C9/($B$2:$B9=B10))