luogu#P7948. [✗✓OI R1] 前方之风
[✗✓OI R1] 前方之风
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.
Problem Description
You are given a sequence of length and queries. The -th query gives . For each query, you need to perform the following operations:
- Compute the average of the remaining numbers.
- Delete the numbers among the remaining ones that satisfy .
- Repeat the above two steps until no numbers will be deleted.
- 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 , denoting the number of testcases.
For each testcase, the first line contains two integers , denoting the number of elements and the number of queries.
The next line contains integers, where the -th integer is .
The next line contains integers, where the -th integer is .
Output Format
Output a total of lines. For each line, output integers, where the -th integer denotes how many numbers will remain after processing the -th query.
5
9 9
19 99 63 39 72 46 97 38 68
0 6 4 0 7 1 0 3 6
6 8
88 62 48 50 8 47
0 6 1 5 2 2 6 1
6 5
33 3 54 17 26 64
87 89 92 70 59
18 19
71 52 77 38 12 34 82 14 57 39 91 7 56 86 35 68 38 14
9 9 1 5 1 3 4 5 6 1 6 0 3 0 2 1 3 5 8
10 15
4 77 78 76 5 19 98 94 77 81
17 43 4 86 2 91 85 4 81 74 44 16 21 69 32
1 2 2 1 2 2 1 2 2
1 1 1 1 1 1 1 1
6 6 6 6 6
4 4 1 3 1 2 2 3 3 1 3 1 2 1 1 1 2 3 4
7 7 2 10 2 10 10 2 10 10 7 7 7 10 7
1
5 1
20 0 0 0 0
5
5
Hint
Sample Explanation
For the first sample, when , obviously only will be left.
When , the deletion steps are as follows:
- The average is , and are kept.
- The average is , and are kept.
- The average is , stop deleting.
Constraints
For of the data, it holds that , , .
| subtask | Special Constraints | Score | Time Limit |
|---|---|---|---|
| 1 | 20 | 300ms | |
| 2 | 30 | ||
| 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."

Translated by ChatGPT 5