Horse Race
Practice
4 (7 votes)
Algorithms
Binary search
Problem
57% Success 1055 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You own a race course where \(N\) different races are played on a day and the performance of the winner is recorded in an array \(A\). The winner of the \(i'th\) race is \(A[i]\) horse. Being the owner, you are only interested in the performance of all the horses numbered from \(1\) to \(M\). Let's denote the number of races won by the horses numbered from \(1\) to \(M\) by array \(B\), where \(B[j]\) denotes the number of races won by horse \(j\) (\(1 \leq j \leq M\)).
Let \(K\) denote the minimum value among all the elements of the array \(B\). You are allowed to perform the following operations at most \(X\) times (maybe 0).

  • Choose index \(i\) (\(1 <= i <= N\)) change the value of \(A[i]\) i.e. the winner of race \(i\).

You are given an integer \(X\) denoting the maximum number of operations you can perform. Find the maximum possible value of \(K\) after performing atmost \(X\) operations.

Note: There can be horses greater than \(M (M \leq N)\) participating in the race, but we only care about the horses numbered from \(1\) to \(M\).

Input Format

  • The first line contains an integer \(T\), which denotes the number of test cases.
  • The first line of each test case contains three integers, denoting the value of \(N\), \(M\), and \(X\) respectively.
  • The second line of each test case contains \(N\) space-separated integers, denoting the elements of array \(A\).

Output Format

For each test case, print the maximum possible value of \(K\).

Constraints

\(1 \leq T \leq 10 \\ 1 \leq N, M, X \leq 10^5 \\ 1 \leq M, A[i] \leq N\)

 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
8 votes
Tags:
Binary SearchImplementationAlgorithmsPointer
Points:30
18 votes
Tags:
AlgorithmsBinary SearchGreatest common divisorMediumSearchinggcd
Points:30
8 votes
Tags:
Binary SearchAlgorithmsGreedy Algorithms