Road to playoffs
Practice
3 (6 votes)
Binary search
Algorithms
Greedy algorithms
Problem
83% Success 1183 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

In a football championship, N teams are competing against each other on the league stage. The current number of points of each team are X1, X2, X3....XN. M days of league stage are remaining and on each day K teams win and each of the winning team's points is incremented by 1. Top B teams will qualify for the playoffs in the championship. Officials of the tournament want to how many teams have a non-zero probability of making it to the playoffs.

Note: If points of certain teams are equal, any of the teams can qualify for playoffs and each team has equal probability.

Input format

  • The first line contains an integer T denoting the number of test cases. For each test case:
  • The first line contains four space-separated integers N, M, K, and B.
  • The second line contains N space-separated integers X1, X2, X3...XN.

Output format

Print T integers. For each test case:

  • Print the number of teams that have a non-zero probability of making it to the playoffs.

Constraints

  • \( 1\leq T \leq 20000\)
  • \(1 \leq N \leq 200000\)
  • \(1 \leq M \leq 10^9\)
  • \(1 \leq B,K < N\)
  • \( 1 \leq X_i \leq 10^9\)
  • Sum of N over all test cases will not exceed 200000.

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:50
11 votes
Tags:
AlgorithmsBinary SearchFenwick TreeHardHiringSearching
Points:50
36 votes
Tags:
AlgorithmsApprovedBinary SearchHardOpenSorting
Points:50
7 votes
Tags:
Binary SearchAlgorithmsC++