Car distance problem in priority queue STL

In car distance problem, can’t we first calculate the distance of all all cars from origin and then push them in min priority queue. Then we can easily pop the k nearest cars using pop in O n time ? Please tell?

Mention problem link

As you are not responding to this thread, I m marking it resolved. You can reopen it if u wanted to.