When traveling with average speed 40 km/h, the car would cover a distance of 80 km in time t such that
40 km/h = (80 km) / t ⇒ t = 2 h
so the total travel time is 2 h + 3 h = 5 h.
Average speed is defined as the total distance traveled divided by the time it took to cover that distance. So if the overall average speed was 30 km/h, then
30 km/h = (80 km + x) / (5 h) ⇒ x = 70 km
where x is the distance traveled in the last 3 h of the trip.
Then the total displacement of the car is 80 km + 70 km = 150 km.