#P12257. Grouping Students by Exam Scores

    ID: 14364 Type: Default 1000ms 256MiB

Grouping Students by Exam Scores

Grouping Students by Exam Scores

There are n students in the class, each with a score given by \(a_i\) for the \(i\)-th student. The teacher wants to form as many groups as possible from the students such that in every group the maximum score is at least twice the minimum score (i.e., \(\max \ge 2\times \min\)).

If it is impossible to arrange all students into one valid group, output \(0\).

Note: Groups must contain at least two students for the condition to possibly hold.

inputFormat

The input consists of two lines:

  • The first line contains an integer \(n\) (\(1 \le n \le 10^5\)) representing the number of students.
  • The second line contains \(n\) integers \(a_1, a_2, \dots, a_n\) (\(1 \le a_i \le 10^9\)), which are the scores of the students.

outputFormat

Output a single integer, the maximum number of valid groups that can be formed. If no valid grouping exists, output \(0\).

sample

5
1 3 2 4 8
2