ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1726. Visits

Accepted simple way how to compute sum of distances
Posted by Gleb Dubosarskii 6 May 2017 21:52
After sorting of array of x and y all you need to do is to compute this two double sums sum(i=1)^n sum(j=1)^(i-1) (x_i-x_j) and sum(i=1)^n sum(j=1)^(i-1) (y_i-y_j). After simplifications one can obtain that they equal
sum(i=1)^n x_i*(2*i-1-n) and sum(i=1)^n y_i*(2*i-1-n).
After computations you divide final sum by C_n^2=n*(n-1)/2 and get required answer.
Re: Accepted simple way how to compute sum of distances
Posted by hduads2020_19321111 29 Mar 2021 20:43
Can you make your Formulations readable?