I have tried an array formula taking the largest average, but that is not always right.

Any ideas how to achieve this?

average.xlsx

Attached is a sample data set and the desired results.