Created
September 15, 2018 10:45
-
-
Save completejavascript/6d65841078311e08a084211e5ae8f59b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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