Skip to content

Instantly share code, notes, and snippets.

@completejavascript
Created September 15, 2018 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save completejavascript/6d65841078311e08a084211e5ae8f59b to your computer and use it in GitHub Desktop.
Save completejavascript/6d65841078311e08a084211e5ae8f59b to your computer and use it in GitHub Desktop.
#include<stdio.h>
const int MAX = 1000005;
int cnt[MAX];
int main()
{
int T;
scanf("%d",&T);
for(int tc = 0; tc < T; tc++)
{
int n;
scanf("%d",&n);
for(int i = 0; i < MAX; i++)
cnt[i] = 0;
for(int i = 0; i < n; i++)
{
int t;
scanf("%d",&t);
cnt[t]++;
}
int max_collection = 0;
for(int i = 0; i < MAX; i++)
{
if((cnt[i]==0) || (2*i >= MAX) || (cnt[2*i]==0)) continue;
if(cnt[i] < cnt[2*i])
{
max_collection += cnt[i];
cnt[2*i] -= cnt[i];
}
else
{
max_collection += cnt[2*i];
cnt[2*i]= 0;
}
}
printf("%d\n",max_collection);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment