#P7856. 「EZEC-9」模糊众数
「EZEC-9」模糊众数
Description
You are given a sequence of length .
You can increase a number in the sequence by , which is called one operation.
You need to process queries.
For each query, find the minimum number of operations needed so that can be turned into a sequence , where is a mode of .
Note: A sequence may have multiple modes.
Input Format
The first line contains two integers .
The second line contains integers .
The next lines each contain one integer .
Output Format
For each query, if there is no solution output -1, otherwise output the minimum number of operations.
Print each answer on a separate line.
6 2
1 1 1 3 3 3
2
10
3
13
Hint
[Sample 1 Explanation]
- When , one feasible plan is .
- When , one feasible plan is .
[Constraints and Notes]
This problem uses bundled tests.
- Subtask 1 (5 points): .
- Subtask 2 (5 points): all are equal, time limit is 2000 ms.
- Subtask 3 (5 points): , .
- Subtask 4 (15 points): , .
- Subtask 5 (15 points): .
- Subtask 6 (15 points): .
- Subtask 7 (40 points): time limit is 2000 ms.
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号