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 aa of length nn and qq queries. The ii-th query gives kik_i. For each query, you need to perform the following operations:

  1. Compute the average avg\mathit{avg} of the remaining numbers.
  2. Delete the numbers among the remaining ones that satisfy <avgki< \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 TT, denoting the number of testcases.
For each testcase, the first line contains two integers n,qn, q, denoting the number of elements and the number of queries.
The next line contains nn integers, where the ii-th integer is aia_i.
The next line contains qq integers, where the ii-th integer is kik_i.

Output Format

Output a total of TT lines. For each line, output qq integers, where the ii-th integer denotes how many numbers will remain after processing the ii-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 k=0k = 0, obviously only 9999 will be left.
When k=6k = 6, the deletion steps are as follows:

  • The average is 601960\dfrac{1}{9}, and 99,63,72,97,6899, 63, 72, 97, 68 are kept.
  • The average is 79.879.8, and 99,9799, 97 are kept.
  • The average is 9898, stop deleting.

Constraints

For 100%100\% of the data, it holds that 1n,q1051 \le n, q \le 10^5, 1T101 \le T \le 10, 0ai,ki1090 \le a_i, k_i \le 10^9.

subtask Special Constraints Score Time Limit
1 n,q200n, q \le 200 20 300ms
2 n,q2000n, q \le 2000 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