code Forces 158A Next Round

来源:互联网 发布:淘宝客活动计划是什么 编辑:程序博客网 时间:2024/04/27 20:30

"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.

Input

The first line of the input contains two integers n andk (1 ≤ k ≤ n ≤ 50) separated by a single space.

The second line contains n space-separated integersa1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got thei-th place. The given sequence is non-increasing (that is, for alli from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).

Output

Output the number of participants who advance to the next round.

Sample Input

Input
8 510 9 8 7 7 7 5 5
Output
6
Input
4 20 0 0 0
Output
0

Hint

In 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.

问题:就是让你找成绩排成一个递减数列中晋级的人;

分析:判断写好就行了...考虑下有几个人相等的时候和其中有0的情况

#include<stdio.h>int main(){int k,n,a[105],t=0,flag=0;scanf("%d %d",&k,&n);for(int i=0;i<k;i++){scanf("%d",&a[i]);}for(int j=0;j<k;j++){if(a[j]&&a[j]>=a[n-1])t++;}printf("%d\n",t);return 0;}


0 0
原创粉丝点击