Fun box packing
InterviewTime limit2sMemory limit512 MB
Given N box sizes, nest a box inside another when the outer size is at least twice the inner, each box holds at most one, and minimize the number of visible (unnested) boxes.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Two pointers, Binary search
- Solved
- No attempts yet
Problem
Minho has N boxes. The pile grew too large, so he wants to tidy it up, but he finds ordinary tidying dull and set two rules to make it more fun.
- Let be the size of box x and the size of box y. You can put box x inside box y if .
- If box x is inside box y, then box y cannot be put inside another box. A box holds at most one other box.
Only a box that is not inside another box is visible. Tidy the boxes under these rules so that the number of visible boxes is as small as possible, and report that minimum.
Input
The first line contains the number of boxes N () that Minho has.
Each of the next N lines contains one box size V ().
Output
Print the smallest possible number of visible boxes on one line.