Algorithms and Data Structures

  • Profound Academy

    • Status
      • 1
        Implementation
      • 2
        Bitwise operations
      • 3
        Prefix Sums
      • 4
        Sliding window / Two pointers
      • 5
        Modular Arithmetic
      • 6
        Number Theory
      • 7
        Binary Search
      • 8
        Basic Sorting
      • 9
        Greedy Algorithms
      • 10
        Basic Dynamic Programming
      • 11
        Recursion
      • 12
        Linked LIst
      • 13
        Queue & Stack
      • 14
        Binary tree + BST
      • 15
        Divide & Conquer + Advanced Sorting
      • 16
        Heap
      • 17
        Hashing
      • 18
        Graph Representation
      • 19
        BFS

  • Hide boxes

    Given n boxes, you would like to hide as many of those boxes inside others as possible. There are several rules that you need to follow:
    1. You can place a small box inside of another larger box only if the larger one is at least twice as large as the small box.
    1. You can place only 1 box inside another box (No box can contain 2 or more other boxes).
    notion image
    What would be the minimum possible number of visible boxes in the end?

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ ) the number of boxes.
    The next line contains n space-separated integers (1 ≤ ) the size of each box.

    Output

    The program should print the least possible number of visible boxes in the end.

    Examples

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

    Explanation

    1. 7 5 2 6 4 8 9 2 → (2, 5) (2, 6) (7) (4, 8) (9)
    1. 3 1 8 2 6 5 6 9 → 1 2 3 5 6 6 8 9 → (1, 5) (2, 6) (3, 6) (8) (9)
     

    Constraints

    Time limit: 1 seconds

    Memory limit: 512 MB

    Output limit: 1 MB

    To check your solution you need to sign in
    Sign in to continue