Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Road to playoffs problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Road to playoffs problem solution 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.
 
 
HackerEarth Road to playoffs problem solution

 

 

HackerEarth Road to playoffs problem solution.

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "n"
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
bool check(vector<ll>&a,ll mid,ll n,ll m,ll k,ll p){
ll total=0;
for(ll i=0;i<n;i++){
if(i+1<p || i>=mid){
total+=m;
}
else{
if(a[i]>a[mid]+m){
return false;
}
total+=(a[mid]+m-a[i]);
}
}
return (total>=m*k);
}
int main() {
FIO;
test
{
ll n,m,k,b; cin>>n>>m>>k>>b;
vector<ll>a(n);
for(auto &it:a) cin>>it;
sort(a.begin(),a.end(),greater<ll>());
ll ans=b,st=b,dr=n-1;
while(st<=dr){
ll mid=(st+dr)/2;
if(check(a,mid,n,m,k,b)){
ans=mid+1;
st=mid+1;
}
else{
dr=mid-1;
}
}
cout<<ans<<endl;
}
return 0;
}
 

Second solution

from math import inf

t = int(input())
while t > 0:
t -= 1
n, m, k, b = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
lo = b - 1
hi = n
while hi - lo > 1:
i = (lo + hi) // 2
need = m * (k - (b - 1) - (n - i))
for j in range(b - 1, i):
if a[j] > a[i] + m:
need = inf
else:
need -= a[i] + m - a[j]
if need > 0:
hi = i
else:
lo = i
print(lo + 1)
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes