#include <iostream> using namespace std; #define MAX_POINTS 120 int main() { int n, k, a; cin >> n; cin >> k; int points[MAX_POINTS + 1]; for (int i = 0; i <= MAX_POINTS; i++) points[i] = 0; for (int i = 0; i < n; i++) { cin >> a; points[a]++; } int kos = 0, i = MAX_POINTS; while (k > 0) { kos += points[i]; k -= points[i]; i--; } cout << kos << endl; 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, a; cin >> n; cin >> k; int points[MAX_POINTS + 1]; for (int i = 0; i <= MAX_POINTS; i++) points[i] = 0; for (int i = 0; i < n; i++) { cin >> a; points[a]++; } int kos = 0, i = MAX_POINTS; while (k > 0) { kos += points[i]; k -= points[i]; i--; } cout << kos << endl; return 0; } |