for the butypair question, JULY 2021 lunch time… My code is as follows and I am getting runtime error SIGSEGV for 2nd subtask … could anyone please tell me why I am getting this and how to solve this ?
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll maxgiver(ll arr[],ll m){
ll k=0;
for(ll i=0; i<m; i++){
k=max(k,arr[i]);
}
return k;
}
int main(){
ll t;
cin>>t;
while(t--){
ll m;
cin>>m;
ll arr[m];
for(ll i=0; i<m; i++){
cin>>arr[i];
}
ll k =maxgiver(arr,m);
ll v[k+1]={0};
for(ll i=0; i<m; i++){
v[arr[i]]++;
}
ll sum=0;
for(ll i=0; i<=k; i++){
if(v[i]>1){
sum+=((v[i])*(v[i]-1));
}
}
cout<<(m*(m-1))-sum<<endl;
}
return 0;
}
Thankyou !