158A-Next Round
A. Next Roundtime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output
"Contestant who earns a score equal to or greater thanK-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 totalNParticipant parts took part in the contest (N? ≥?K), And you already know their scores. Calculate how to adjust the participation to the next round.
Input
The first line of the input contains two integersNAndK(1? ≤?K? ≤?N? ≤? 50) separated by a single space.
The second line containsNSpace-separated integersA1 ,?A2 ,?...,?AN(0? ≤?AI? ≤? 100), whereAIIs the score earned by the participating ipant who gotI-Th place. The given sequence is non-increasing (that is, for allIFrom 1N? -? 1 the following condition is fulfilled:AI? ≥?AI? +? 1 ).
Output
Output the number of maid who advance to the next round.
Sample test (s) input
8 510 9 8 7 7 7 5 5
Output
6
Input
4 20 0 0 0
Output
0
Note
In the first example the particle ant on the 5th place earned 7 points. As the particle ant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score.
import java.util.*;public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); int count=0; int[] score = new int[60]; for(int i=0;i
=max&&score[i]>0) count++; System.out.println(count); }}