A. Hossam and Combinatorics
Hossam woke up bored, so he decided to create an interesting array with his friend Hazem.
Now, they have an array of positive integers, Hossam will choose a number and Hazem will choose a number .
Count the number of interesting pairs that meet all the following conditions:
- ;
- ;
- The absolute difference must be equal to the maximum absolute difference over all the pairs in the array. More formally, .
The input consists of multiple test cases. The first line contains a single integer (), which denotes the number of test cases. Description of the test cases follows.
The first line of each test case contains an integer ().
The second line of each test case contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
code of this question -----------------
- void solve()
- {
- int n;
- cin>>n;
- // int arr[n];
- // int min = INT_MAX;
- // int max = INT_MIN;
- map<int,int> mp;
- vector<int> arr(n);
- for(int i=0; i<n; ++i)
- {
- cin>>arr[i];
- mp[arr[i]]++;
- }
- sort(arr.begin(),arr.end());
- if(mp[arr[0]]==n)
- {
- cout<<n*(n -1)<<endl;
- }else{
- cout<<2*(mp[arr[0]]*mp[arr[n-1]])<<endl;
- }


No comments:
Post a Comment