#include <cstdio> #include <algorithm> constexpr int MAX_SCORE = 121; int buckets[MAX_SCORE]; int main() { int n, k, score; scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &score); buckets[score]++; } int result = 0; int iter = MAX_SCORE - 1; while (result < k) { result += buckets[iter]; iter--; } printf("%d\n", result); 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 | #include <cstdio> #include <algorithm> constexpr int MAX_SCORE = 121; int buckets[MAX_SCORE]; int main() { int n, k, score; scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) { scanf("%d", &score); buckets[score]++; } int result = 0; int iter = MAX_SCORE - 1; while (result < k) { result += buckets[iter]; iter--; } printf("%d\n", result); return 0; } |