You could also add in another column with AND function :
So for cells below, in column E you could have expression in cell E5 something like
=AND(D5=40,ABS(D6-40)<0.1,ABS(D7-40)<0.1,SUM($E$4:E4)=0)*C5
The answer is found by summing all column E or looking for max in column E.
C D E F G H
4...