Maximum pairs

2

3 votes
Binary Search, Binary search algorithm, Algorithms, Searching algorithm
Problem

You are given N pencils. You have to make pairs of these pencils. The condition for making pairs is:

If (a,b) is any pair of pencils, then b2×a. Here a and b are the sizes of pencils.

Now, your task is to determine the number of such pairs and the number of pencils that could not be paired with any pencils.

Input format

  • The first line consists of the number of test cases T.
  • For each test case:
    • The first line consists of a single integer N.
    • The second line consists of N space-separated integers denoting the size of pencils Si.

Output format

For each test case, print two space-separated integers where the first integer denotes the number of pairs formed and the second integer denotes the number of unpaired pencils.
The answer to each test case must be printed in a new line.

Constraints
1T10
1N105
0Si105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

In the first test case :-
we can form the following pairs
(1,3)(2,4) and 5 remains unpaired hence maximum pairs are 2
In second test case :-
(1,4)(2,4) are two pairs hence no pencil left unpaired

Editor Image

?