A. Counting Kangaroos is Fun

There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.

Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos.

The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.

Input

The first line contains a single integer — n (1 ≤ n ≤ 5·105). Each of the next n lines contains an integer si — the size of the i-th kangaroo (1 ≤ si ≤ 105).

Output

Output a single integer — the optimal number of visible kangaroos.

Sample test(s)
input
8
2
5
7
6
9
8
4
2
output
5
input
8
9
1
6
2
6
5
8
3
output
5





#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;

 int f[500050];

int main()
{  
int i,n;

scanf("%d",&n);
for(i=1;i<=n;i++)
{
	scanf("%d",&f[i]);
}


sort(f+1,f+n+1);
 


int p_n=n;

for (i=n/2;i>=1;i--)             //关键是这个点没clear,之前一直认为f[n]/2是最大能隐藏的袋鼠个数,然后必须从小于等于他的数开始放进大袋鼠
//里    实际是错的,最有应该是 从 n/2的位置开始搜索。才是最优。。。理解上的问题
{
  if (f[i]*2<=f[p_n] )
  {
	  p_n--;
  }
}

printf("%d\n",p_n);

	return 0;
	
}	 



#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;

 int f[500050];

int main()
{  
int i,n;

scanf("%d",&n);
for(i=1;i<=n;i++)
{
	scanf("%d",&f[i]);
}


sort(f+1,f+n+1);
 


int p_n=n;

for (i=n/2;i>=1;i--)
{
  if (f[i]*2<=f[p_n] )
  {
	  p_n--;
  }
}

printf("%d\n",p_n);

	return 0;
	
}	 

你可能感兴趣的:(A. Counting Kangaroos is Fun)