#include <iostream>
#include <stdio.h>
using namespace std;
int tab[121];
int main() {
// your code goes here
int n,k,a;
scanf("%d%d",&n,&k);
while(n--)
{
scanf("%d",&a);
tab[a]++;
}
int s=0;
int i=120;
while (s<k && i>=0)
{
s+=tab[i];
i--;
}
printf("%d\n",s);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <iostream> #include <stdio.h> using namespace std; int tab[121]; int main() { // your code goes here int n,k,a; scanf("%d%d",&n,&k); while(n--) { scanf("%d",&a); tab[a]++; } int s=0; int i=120; while (s<k && i>=0) { s+=tab[i]; i--; } printf("%d\n",s); return 0; } |
English