"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.InputThe first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space.The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).OutputOutput the number of participants who advance to the next round.ExamplesinputCopy8 510 9 8 7 7 7 5 5outputCopy6inputCopy4 20 0 0 0outputCopy0NoteIn the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.In the second example nobody got a positive score.
Question
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.InputThe first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space.The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).OutputOutput the number of participants who advance to the next round.ExamplesinputCopy8 510 9 8 7 7 7 5 5outputCopy6inputCopy4 20 0 0 0outputCopy0NoteIn the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.In the second example nobody got a positive score.
Solution
Para resolver este problema, podemos seguir los siguientes pasos:
- Leer los valores de
nyk. - Leer la lista de puntajes
a. - Determinar el puntaje del participante en la posición
k(recordando que la lista está en orden no creciente). - Contar cuántos participantes tienen un puntaje mayor o igual al puntaje del participante en la posición
ky que además tengan un puntaje positivo.
Aquí está el código que implementa estos pasos:
# Leer los valores de n y k
n, k = map(int, input().split())
# Leer la lista de puntajes
a = list(map(int, input().split()))
# Determinar el puntaje del k-ésimo participante
kth_score = a[k-1]
# Contar cuántos participantes avanzan a la siguiente ronda
count = 0
for score in a:
if score >= kth_score and
Similar Questions
Problem StatementIn a gaming tournament, players are ranked in ascending order based on their scores. Your task is to design a program using binary search to determine the score of the player positioned at the kth place, enabling the organizers to swiftly identify individual performance levels. The program takes the total number of players, their sorted scores, and the rank (k) as input, and outputs the score of the player ranked at the kth position(position value starts from 1).Input format :The first line of input consists of an integer N, representing the total number of players in the tournament.The second line consists of N distinct space-separated integers, representing the sorted list of players' scores.The third line consists of an integer k, representing the rank of the player whose score needs to be determined.Output format :The output prints a single integer, representing the score of the player ranked at position k in the tournament.Code constraints :1 ≤ N ≤ 101 ≤ score ≤ 1001 ≤ k ≤ NSample test cases :Input 1 :712 15 34 47 49 57 583Output 1 :34Input 2 :624 25 37 48 98 995Output 2 :98
In a coding contest, there are prizes for the top rankers. The prize scheme is as follows:Top 1010 participants receive rupees 𝑋X each.Participants with rank 1111 to 100100 (both inclusive) receive rupees 𝑌Y each.Find the total prize money over all the contestants.Input FormatFirst line will contain 𝑇T, number of test cases. Then the test cases follow.Each test case contains of a single line of input, two integers 𝑋X and 𝑌Y - the prize for top 1010 rankers and the prize for ranks 1111 to 100100 respectively.Output FormatFor each test case, output the total prize money over all the contestants.Constraints1≤𝑇≤10001≤T≤10001≤𝑌≤𝑋≤10001≤Y≤X≤1000Sample 1:InputOutput41000 1001000 100080 1400 30190001000008906700Explanation:Test Case 11: Top 1010 participants receive rupees 10001000 and next 9090 participants receive rupees 100100 each. So, total prize money =10⋅1000+90⋅100=19000=10⋅1000+90⋅100=19000.Test Case 22: Top 1010 participants receive rupees 10001000 and next 9090 participants receive rupees 10001000 each. So, total prize money =10⋅1000+90⋅1000=100000=10⋅1000+90⋅1000=100000.Test Case 33: Top 1010 participants receive rupees 8080 and next 9090 participants receive rupee 11 each. So, total prize money =10⋅80+90⋅1=890=10⋅80+90⋅1=890.Test Case 44: Top 1010 participants receive rupees 400400 and next 9090 participants receive rupees 3030 each. So, total prize money =10⋅400+90⋅30=6700=10⋅400+90⋅30=6700.
Input format :The first line contains an integer 't' representing the number of test cases.Each test case consists of a single line with two space-separated integers 'x' and 'y', representing the scores of Sasha and Brenda, respectively, for a particular round.Output format :For each test case, the output prints the result of that round.If x is greater than y, the output prints "Sasha".If x is equal to y, the output prints "Tie".Otherwise, the output prints "Brenda"
Write a Java program that reads an unspecified number of scores anddetermines how many scores are above or equal to the average, and how many scoresare below the average. Enter a negative number to signify the end of the input. Assumethe maximum number of scores is 100.
The first line of input consists of an integer N, representing the number of tickets.The second line consists of N space-separated integers, representing the ticket numbers.The third line consists of an integer X, representing the ticket number to search.Output format :If the ticket number is found, print "Congratulations! Ticket number X found at position Y!", where X is the ticket number and Y is the position (position starts from 1).Otherwise, print "Better luck next time! Ticket number X not found!", where X is the ticket number.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.