#include <algorithm> #include <cstdio> using namespace std; int t[128]; int N, K; int main() { scanf("%d%d", &N, &K); for (int x, i = 0; i < N; ++i) { scanf("%d", &x); t[x]++; } int sum = 0; for (int i = 127; i >= 0 && sum < K; --i) sum += t[i]; printf("%d\n", sum); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <algorithm> #include <cstdio> using namespace std; int t[128]; int N, K; int main() { scanf("%d%d", &N, &K); for (int x, i = 0; i < N; ++i) { scanf("%d", &x); t[x]++; } int sum = 0; for (int i = 127; i >= 0 && sum < K; --i) sum += t[i]; printf("%d\n", sum); return 0; } |