I have two arrays:
score[n]
pos[n]
, where n <= 10^5; pos[i],score[i] <= 10^4
Define:
f(i,j) = abs(pos[i]-pos[j])*max(score[i],score[j])
I need to find sum of f(i,j)
for all i,j
s.
I have an algorithm that can solve it in O(n^2)
but i want to optimize.
I have spent much time but could not.
Any help is appreciated. Worst case code http://ideone.com/q4qSNh