Jackie is analysing some payment data, stored in
cents, and wants to find pairs of payments that add
up to whole dollar amounts (e.g., 100, 200, 300).
Given a list of payments, calculate the to total
number of payment pairs that can be made.
Answers
Answered by
2
Answer:
If |a[j]-a[i]| > 1
f(a[i], a[j]) = a[j] - a[i]
Else // if |a[j]-a[i]| <= 1
f(a[i], a[j]) = 0
Examples:
Input : 6 6 4 4
Output : -8
Explanation:
All pairs are: (6 - 6) + (6 - 6) +
(6 - 6) + (4 - 6) + (4 - 6) + (4 - 6) +
(4 - 6) + (4 - 4) + (4 - 4) = -8
Input: 1 2 3 1 3
Output: 4
Explanation: the pairs that add up are:
(3, 1), (3, 1) to give 4, rest all pairs
according to condition gives 0.
Recommended: Pleas
Similar questions