水题:Counting Kangaroos is Fun

Description

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 Input

Input
8
2
5
7
6
9
8
4
2
Output
5
Input
8
9
1
6
2
6
5
8
3
Output
5

 

 1 #include <cstdio>

 2 #include <iostream>

 3 #include <cstring>

 4 #include <string>

 5 #include <algorithm>

 6 

 7 using namespace std;

 8 

 9 const int MAX = 5e5 + 10;

10 

11 int arr[MAX];

12 

13 int main()

14 {

15 #ifdef OFFLINE

16     freopen("in.txt", "r", stdin);

17     freopen("out.txt", "w", stdout);

18 #endif

19 

20     int n;

21     while (~scanf("%d", &n))

22     {

23         memset(arr, 0, sizeof(arr));

24 

25         for (int i = 0; i < n; i++)

26             scanf("%d", &arr[i]);

27 

28         sort(arr, arr + n);

29         reverse(arr, arr + n);

30 

31         int crt = 0, ans = (n + 1) / 2;

32         for (int i = (n + 1) / 2; i < n; i++)

33             if (arr[i] * 2 <= arr[crt])

34                 crt++;

35             else

36                 ans++;

37 

38         printf("%d\n", ans);

39     }

40 

41     return 0;

42 }
View Code

 

你可能感兴趣的:(count)