#include <iostream> #include <array> namespace { using std::cin; using std::cout; using std::array; inline size_t const MAX_SCORE = 120; } int main() { size_t n, k; array<size_t, MAX_SCORE> scores{}; size_t read_score; cin >> n; cin >> k; while (cin >> read_score) ++scores[read_score - 1]; size_t i = MAX_SCORE - 1; size_t shirt_counter = 0; while (shirt_counter < k) { shirt_counter += scores[i]; --i; } cout << shirt_counter; 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 | #include <iostream> #include <array> namespace { using std::cin; using std::cout; using std::array; inline size_t const MAX_SCORE = 120; } int main() { size_t n, k; array<size_t, MAX_SCORE> scores{}; size_t read_score; cin >> n; cin >> k; while (cin >> read_score) ++scores[read_score - 1]; size_t i = MAX_SCORE - 1; size_t shirt_counter = 0; while (shirt_counter < k) { shirt_counter += scores[i]; --i; } cout << shirt_counter; return 0; } |