#P7856. 「EZEC-9」模糊众数

「EZEC-9」模糊众数

Description

You are given a sequence aa of length nn.

You can increase a number in the sequence by 11, which is called one operation.

You need to process qq queries.

For each query, find the minimum number of operations needed so that aa can be turned into a sequence aa', where xx is a mode of aa'.

Note: A sequence may have multiple modes.

Input Format

The first line contains two integers n,qn,q.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n.

The next qq lines each contain one integer xx.

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 x=2x=2, one feasible plan is a=[1,2,2,3,3,4]a'=[1,2,2,3,3,4].
  • When x=10x=10, one feasible plan is a=[1,2,3,4,5,10]a'=[1,2,3,4,5,10].

[Constraints and Notes]

This problem uses bundled tests.

  • Subtask 1 (5 points): n=3n=3.
  • Subtask 2 (5 points): all aia_i are equal, time limit is 2000 ms.
  • Subtask 3 (5 points): n10n\le 10, q103q\le 10^3.
  • Subtask 4 (15 points): n100n\le 100, q104q\le 10^4.
  • Subtask 5 (15 points): n103n\le 10^3.
  • Subtask 6 (15 points): q103q\le 10^3.
  • Subtask 7 (40 points): time limit is 2000 ms.

For 100%100\% of the testdata, 1n,q1051\le n,q\le 10^5, 1ai,x1091\le a_i,x\le 10^9.

Translated by ChatGPT 5