You can add 2 helper columns to your table like so:
Col D tracks the last Elevation that met your criteria. Similarly, Col E selects the last Distance that met your criteria. This keep COL F's formula super simple.
Note this is a variation on Alan's comment, but I prefer the legibility and maintainability of the additional columns to the expert level (and lengthy) formula.