Average speed is total distance over total time. The distances are 30×2=60 and 50×3=150 miles, so the total is 210 miles in 5 hours.
average speed=5210=42 mph
The plain mean of 30 and 50 is 40, but more time was spent at 50 mph, so the average is higher.