Building Snowmen
InterviewTime limit1sMemory limit128 MB
Given snowball diameters, find the maximum number of triples where each triple's sizes satisfy the stacking ratio inequalities.
- Level
Medium6 of 10
- Topics
- Greedy, Sorting, Two pointers, Binary search
- Solved
- No attempts yet
Problem
You want to build an army of snowmen. To do so, you have gathered a bunch of snowballs of varying sizes. Each snowman is built by stacking three snowballs on top of one another: first choose a snowball for the base, then a smaller one for the middle, and finally an even smaller one for the top.
Each snowball has a diameter . For a given snowman, let the diameter of the base snowball be , the diameter of the middle snowball be , and the diameter of the top snowball be . Then both of the following inequalities must hold:
Compute the maximum number of snowmen that can be built from the available snowballs while satisfying these conditions.
Input
The first line contains the number of data sets . Then data sets follow, each in the form below.
The first line of each data set contains the number of snowballs (). The next line contains integers, each between and inclusive. The -th integer is the diameter of the -th snowball.
Output
For each data set, first output Data Set x: on its own line, where is the data set's number. On the next line, output the maximum number of proper snowmen that can be completed. Separate consecutive data sets with a single blank line.