Comments

Hungarian algorithm may be the solution in O(n*log n).

I've seen the similar problem and solution in Edu#97 problem C.

https://mirror.codeforces.com/blog/entry/84149

The rating result sooner or later will came out, Don't worry about that.

You can check out the unofficial rating prediction in https://cf-predictor-frontend.herokuapp.com

It's pretty accurate.

pD and Edu#97 pC is almost the same.

Maybe the Editorial here ( https://mirror.codeforces.com/blog/entry/84149 ) may help you.