Ali's schedule this month is packed due to Ramadan, Midterms, and the Ramadan Coding Marathon.
Ali wants to keep up with all the things happening during this busy month, so he decided to write a to-do list.
Ali has $n$ days with $n$ tasks to finish, so he has assigned a priority for each task. The more important a task is, the smaller the value assigned to it.
Ali will do his tasks as follows: on each day, Ali starts by calculating the average value of the priorities of all the remaining tasks, and then does all the tasks that have a priority strictly less than the average priority value he calculated (if any).
Can you calculate what the priorities of the remaining tasks would be on the list after the $n$ days have passed (if any)?
The first line contains one integer $T$, the number of test cases.
Each test case consists of two lines, the first line contains $n$ $(1 \le n \le 10^5)$, the number of tasks.
The second line contains $n$ space-separated integers $a_1, a_2, ..., a_n$ the priorities of the tasks (task $i$ has priority $a_i$) such that $(1 \le a_i \le 10^9)$ for every $i$ from $1$ to $n$.
It's guaranteed that the sum of $n$ over all test cases doesn't exceed $5\times 10^5$.
Print a list of integers containing the priorities of the remaining tasks separated by spaces and sorted by their order of presence in the array, or -1 if there are none.
Input | Output |
---|---|
2 4 1 2 3 4 2 3 3 Copy
|
4 3 3 Copy
|
On each day, we have two cases:
And since we have $n$ days and $n$ tasks on the to-do list, then we know for sure that we'll be able to do all the tasks that have priority less than the maximum value present in the list, which will then lead us to the first case (above) and that's where we'll stop.
In other words, the tasks left on the to-do list are those sharing the maximum value of priority present on the list.