Sorting based on gain