#include <algorithm> #include <cstdio> #include <vector> #include <set> using namespace std; long a[121]; int main() { long n, k, l; scanf("%ld %ld", &n, &k); for (long i = 0; i < n; ++i) { scanf("%ld", &l); a[l]++; } long res = 0; long i = 120; while (res < k && i >= 0) res += a[i--]; printf("%ld", res); 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 27 | #include <algorithm> #include <cstdio> #include <vector> #include <set> using namespace std; long a[121]; int main() { long n, k, l; scanf("%ld %ld", &n, &k); for (long i = 0; i < n; ++i) { scanf("%ld", &l); a[l]++; } long res = 0; long i = 120; while (res < k && i >= 0) res += a[i--]; printf("%ld", res); return 0; } |