#include <cstdio> #include <functional> #include <algorithm> using namespace std; const int NMAX = 2007; int n, k; int a[NMAX]; int main() { scanf("%d %d", &n, &k); for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n, greater<>()); int j; for(j = k - 1; j < n; j++) if(a[j] != a[j + 1]) break; printf("%d", j + 1); 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 26 | #include <cstdio> #include <functional> #include <algorithm> using namespace std; const int NMAX = 2007; int n, k; int a[NMAX]; int main() { scanf("%d %d", &n, &k); for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n, greater<>()); int j; for(j = k - 1; j < n; j++) if(a[j] != a[j + 1]) break; printf("%d", j + 1); return 0; } |