Sort the input
each
If you're not sure, AtCoder ABC 186 D --Sum of difference (brown, 400 points)
Sample code
n = int(input())
a = list(map(int,input().split()))
a.sort()
suma= sum(a)
ans = 0
for i in range(n-1):
    # print()
    suma -= a[i]
    ans += suma - a[i]*(n-i-1) 
 
print(ans)
        Recommended Posts