Codeforces Round #837 (Div. 2) 1771A Hossam and Combinatorics Solution
Problem Link: https://codeforces.com/contest/1771/problem/A
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- int main()
- {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- ll n,i,t,j ;
- cin>>t;
- while(t--)
- {
- cin>>n;
- ll a[n+1];
- set<ll>st;
- ll mn=1e9,mx=0;
- map<ll,ll>mp;
- for(i=0; i<n; i++)
- {
- cin>>a[i];
- st.insert(a[i]);
- mp[a[i]]++;
- mn=min(a[i],mn);
- mx=max(a[i],mx);
- }
- ll x=mp[mn],y=mp[mx],ans=0;
- for(i=1; i<=x; i++)
- {
- for(j=1; j<=y; j++)
- {
- ans+=2;
- }
- }
- if(st.size()==1)cout<<n*(n-1)<<endl;
- else
- cout<<ans<<endl;
- }
- return 0;
- }
No comments