There is 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 the kangaroo, the kangaroo are at least TWI Ce as large as the size of kangaroo is held.
Each kangaroo can hold on the most one kangaroo, and the kangaroo are held by another kangaroo cannot on any kangaroos.
The kangaroo who are held by another kangaroo cannot are 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 Kang Aroo (1?≤? si? ≤?105).
Output
Output a single integer-the optimal number of visible kangaroos.
Sample Test (s)
Input
825769842
Output
5
Input
891626583
Output
5
The trick is that the smallest K-Kangaroo will be included in the largest k, and the second point will be K.
import java.io.bufferedreader;import java.io.ioexception;import java.io.inputstreamreader; Import java.util.arrays;public class cf372a {private static int[] s;private static int n;public static void main (String[] args) throws Ioexception {bufferedreader in = new bufferedreader (New InputStreamReader ( system.in)); N = integer.parseint (In.readline ());s = new int[n];for (int i = 0; i < n; i++) {s[i] = integer.parseint (In.readLine ());} Arrays.sort (s);int lo = 0, hi = n / 2;while (lo <= hi) {int mid = lo + (hi - lo) / 2;if (OK (mid)) {if (LO&NBSP;==&NBSP;N&NBSP;/&NBSP;2) {break;} lo = mid + 1;} else {hi = mid - 1;}} SysTem.out.println (N - lo);} Private static boolean ok (int x) {for (int i = 0; i <= x; i++) {if (2 * s[x - i] > s[n - i -&NBSP;1]) {return false;}} Return true;}}
The time of submission is stuck. When it can be fully contained, Lo will still increment +1, think for a long time can only trickery at lo = = N/2 when the break off
Codeforces 372A counting Kangaroos is fun