#include <iostream> using namespace std; int main() { int maxPoints = 120; int n, k; cin >> n >> k; int *pointsCount = new int[maxPoints]; // fill_n(pointsCount, maxPoints, 0); for (int i = 0; i < n; i++) { int points; cin >> points; pointsCount[points - 1] += 1; } int shirtsGiven = 0; for (int j = maxPoints - 1; j >= 0; j--) { if (shirtsGiven < k) { shirtsGiven += pointsCount[j]; } else { break; } } cout << shirtsGiven; }
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 | #include <iostream> using namespace std; int main() { int maxPoints = 120; int n, k; cin >> n >> k; int *pointsCount = new int[maxPoints]; // fill_n(pointsCount, maxPoints, 0); for (int i = 0; i < n; i++) { int points; cin >> points; pointsCount[points - 1] += 1; } int shirtsGiven = 0; for (int j = maxPoints - 1; j >= 0; j--) { if (shirtsGiven < k) { shirtsGiven += pointsCount[j]; } else { break; } } cout << shirtsGiven; } |