158A-Next Round

Source: Internet
Author: User

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);    }}
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.