#include <iostream> #include <algorithm> using namespace std; int in[2021]; int main() { int n, k, shirts; cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> in[i]; } sort(in, in + n, greater<int>()); shirts = k; for (int i = k - 1; i < n; ++i) { if (in[i] == in[i + 1]) { shirts++; } else { break; } } cout << shirts << "\n"; }
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 | #include <iostream> #include <algorithm> using namespace std; int in[2021]; int main() { int n, k, shirts; cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> in[i]; } sort(in, in + n, greater<int>()); shirts = k; for (int i = k - 1; i < n; ++i) { if (in[i] == in[i + 1]) { shirts++; } else { break; } } cout << shirts << "\n"; } |