P7948 [✗✓OI R1] Wind Ahead

Background

> "Not bad malice." > The woman chuckled. > "But if you show malice toward me, you will die." You do not know what actions will be considered as showing malice, so you decide to solve a problem to distract yourself.

Description

You are given a sequence $a$ of length $n$ and $q$ queries. The $i$-th query gives $k_i$. For each query, you need to perform the following operations: 1. Compute the average $\mathit{avg}$ of the remaining numbers. 2. Delete the numbers among the remaining ones that satisfy $< \mathit{avg} - k_i$. 3. Repeat the above two steps until no numbers will be deleted. 4. Output how many numbers will remain in the end. **Note: Queries are independent. That is, the numbers are not actually deleted.**

Input Format

**This problem has multiple testcases.** The first line contains an integer $T$, denoting the number of testcases. For each testcase, the first line contains two integers $n, q$, denoting the number of elements and the number of queries. The next line contains $n$ integers, where the $i$-th integer is $a_i$. The next line contains $q$ integers, where the $i$-th integer is $k_i$.

Output Format

Output a total of $T$ lines. For each line, output $q$ integers, where the $i$-th integer denotes how many numbers will remain after processing the $i$-th query.

Explanation/Hint

**Sample Explanation** For the first sample, when $k = 0$, obviously only $99$ will be left. When $k = 6$, the deletion steps are as follows: - The average is $60\dfrac{1}{9}$, and $99, 63, 72, 97, 68$ are kept. - The average is $79.8$, and $99, 97$ are kept. - The average is $98$, stop deleting. **Constraints** For $100\%$ of the data, it holds that $1 \le n, q \le 10^5$, $1 \le T \le 10$, $0 \le a_i, k_i \le 10^9$. | subtask | Special Constraints | Score | Time Limit | | :----------: | :----------: | :----------: | :----------: | | 1 | $n, q \le 200$ | 20 | 300ms | | 2 | $n, q \le 2000$ | 30 | 300ms | | 3 | | 50 | 800ms | > "Not bad malice." > The woman chuckled. > "And you are quite lucky. If it were in the past, you would have died long ago." ![](https://cdn.luogu.com.cn/upload/image_hosting/6icoj36r.png) Translated by ChatGPT 5