F - Pair Sum
CodeChefOpen on judge ↗
You are given an array $a1,a2,…,aN$ of length N. Find the sum of |ai - aj| for all pairs of indexes (i, j) (1Test case 1: Sum is equal to = |1 - 2| + |1 - 3| + |2 - 3| = 1 + 2 + 1 = 4 Test case 2: Sum is equal to = |4 - 5| + |4 - 10| + |4 - 14| + |5 - 10| + |5 - 14| + |10 - 14| = 35
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start