Codeforces 372A counting Kangaroos is fun

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.