#include <iostream> using namespace std; #define MAX_POINTS 120 int main() { int n, k; cin >> n >> k; int *buckets = new int[MAX_POINTS+1]; int point; for (int i=0;i<=MAX_POINTS;++i) { buckets[i] = 0; } for (int i=0;i<n;++i) { cin >> point; buckets[point]++; } int res = 0; for (int i=MAX_POINTS;i>=0;--i) { res += buckets[i]; if (res >= k) break; } cout << 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 28 29 30 31 32 33 34 35 | #include <iostream> using namespace std; #define MAX_POINTS 120 int main() { int n, k; cin >> n >> k; int *buckets = new int[MAX_POINTS+1]; int point; for (int i=0;i<=MAX_POINTS;++i) { buckets[i] = 0; } for (int i=0;i<n;++i) { cin >> point; buckets[point]++; } int res = 0; for (int i=MAX_POINTS;i>=0;--i) { res += buckets[i]; if (res >= k) break; } cout << res; return 0; } |