Distribute candies

my code is failing only in one test case , help me in figuring out what I am missing.
MY CODE

#include
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n,temp;
cin>>n;
unordered_map<ll,ll>m;
for(ll i=0;i<n;i++)
{
cin>>temp;
m[temp]++;
}
ll ones=0,g=0;
for(auto x:m)
{
if(x.second==1)ones++;
else g++;
}
if(ones%2)g+=(ones/2)+1;
else g+=ones/2;
cout<<g<<endl;
return 0;
}

please share code in cb ide @akshugoyal705

image
what is the logic in these lines

like what i think of is

min( m.size() , n/2) should be the answer obviously after adding elements to the map

I got it,I understood my mistake in my logic.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.