P18047 [GeeksforGeeks] Number of pairs with maximum sum2924
普及-
题目描述

Given an array arr[], count number of pairs arr[i], arr[j] such that arr[i] + arr[j] is maximum and i < j.
Example 1:
Input : Arr[] = {1, 1, 1, 2, 2, 2}
Output : 3
Explanation:
We have an array [1, 1, 1, 2, 2, 2]
The maximum possible pair
sum where i is less than j is 4, which
is given by 3 pairs, so the answer is 3
the pairs are (2, 2), (2, 2) and (2, 2).
Example 2:
Input : Arr[] = {1, 4, 3, 3, 5, 1}
Output : 1

Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function MaximumSum() that takes an array (arr), sizeOfArray (n), and return the number of pairs whose sum is maximum. The driver code takes care of the printing.
Expected Time Complexity: O(N).
Expected Auxiliary Space: O(1).
CONSTRAINTS:
1 ≤ a[i], n ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
Arr[] = {1, 1, 1, 2, 2, 2}
样例输出
3