Qualifying to Pre-Elimination CodeChef SnackDown 2021 Beginner Practice Contest
Question:
Snackdown 2019 is coming! There are two rounds (round A and round B) after the qualification round. From both of them, teams can qualify to the pre-elimination round. According to the rules, in each of these two rounds, teams are sorted in descending order by their score and each team with a score greater or equal to the score of the team at the -th place advances to the pre-elimination round (this means it is possible to have more than qualified teams from each round in the case of one or more ties after the -th place).
Today, the organizers ask you to count the number of teams which would qualify for the pre-elimination round from round A for a given value of (possibly different from ). They provided the scores of all teams to you; you should ensure that all teams scoring at least as many points as the -th team qualify.
Input:
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains two space-separated integers and .
- The second line contains space-separated integers .
Output:
Constraints:
- for each valid
- the sum of for all test cases does not exceed
Example Input:
2
5 1
3 5 2 4 5
6 4
6 5 4 3 2 1
Example Output:
2
4
Program Code In C++:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
// your code goes here
ll t;
cin>>t;
while(t--){
ll n,k,c=0;
cin>>n>>k;
vector<ll>a(n);
for(ll i=0;i<n;i++)
cin>>a[i];
sort(a.begin(),a.end(),greater<>());
ll score=a[k-1];
for(ll i=0;i<n;i++){
if(a[i]>=score){
c++;
}
else
{
break;
}
}
cout<<c<<endl;
}
return 0;
}
More Information
CodeChef is one of the largest online coding platform and SnackDown is one of it's of grandest programs held ever year. SnackDown is a global programming event that invites programmers all over the world to participate in India's most prestigious multi-round programming competition. SnackDown is open to everyone who has a knack in programming.
This question that is Qualifying to Pre-Elimination is of CodeChef SnackDown 2021 Beginner Practice Contest. Here you will get a brief explanation of the problem and after reading the explanation if you are still stuck and have no clue to understand the problem then you can visit the solution of the question given above.
Hope you learnt something from this explanation and solution. Code it guys, practice coding more and more.
Comments
Post a Comment