Codeforce Round #219 Div2 C
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.
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 a single integer — the optimal number of visible kangaroos.
8
2 5 7 6 9 8 4 2
5
8
9 1 6 2 6 5 8 3
5
1 #include <cstdio> 2 #include <vector> 3 #include <cmath> 4 #include <queue> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 using namespace std; 9 #define INF 0x7fffffff 10 #define mod 1000000007 11 #define ll unsigned long long int 12 #define maxn 1005 13 int n, w, k, m, ans; 14 int dp[maxn][maxn]; 15 int a[101000]; 16 int main(){ 17 cin >> n; 18 for (int i = 1; i <= n; i++)cin >> a[i]; 19 sort(a + 1, a + n + 1); 20 int i = n,j = n / 2,ans=0; 21 while (i>=n/2&&j>0){ 22 if (a[i] >= 2 * a[j])i--, j--, ans++; 23 else j--; 24 } 25 cout << n-ans; 26 return 0; 27 }
浙公网安备 33010602011771号