牛客网暑期ACM多校训练营(第四场) G Maximum Mode

  • 2018-08-06
  • 27
  • 0

题目:

The mode of an integer sequence is the value that appears most often. Chiaki has n integers a_1,a_2,…,a_n. She woud like to delete exactly m of them such that: the rest integers have only one mode and the mode is maximum.

Input:

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains two integers n and m (1 ≤ n ≤ 10^5, 0 ≤ m < n) — the length of the sequence and the number of integers to delete.
The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^9) denoting the sequence.
It is guaranteed that the sum of all n does not exceed 10^6.

Output:

For each test case, output an integer denoting the only maximum mode, or -1 if Chiaki cannot achieve it.

Sample Input:

5
5 0
2 2 3 3 4
5 1
2 2 3 3 4
5 2
2 2 3 3 4
5 3
2 2 3 3 4
5 4
2 2 3 3 4

Sample Output:

-1
3
3
3
4

题目链接

枚举每种数字个数中的最大值为答案,判断是否可以删除其它数使其成为众数,取最大值。

AC代码:

评论

还没有任何评论,你来说两句吧