question link: here
My code:
#include <bits/stdc++.h>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int a[2000010],ar[105];
int main()
{
int t,n,x,ans;
cin>>t;
while(t--)
{
memset(a,0,sizeof a);ans=0;
cin>>n;
rep(i,n)
{
cin>>x;
a[x]++;
ar[i]=x;
}
sort(ar,ar+n);//without this line solution is wrong.why??
rep(i,n) if(a[ar[i]*2]>0&&a[ar[i]]>0) {++ans;a[ar[i]*2]--;a[ar[i]]--;}
cout<<ans<<"\n";
}
return 0;
}
I think there is no need to sort the array ar[].But it is needed why??
Please help anyone ???