#include <iostream> #include <algorithm> using namespace std; const int MAX_P = 2048; int r[MAX_P]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> r[i]; } sort(r, r + n, greater<int>()); while (k < n && r[k] == r[k - 1]) { ++k; } cout << k << 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 | #include <iostream> #include <algorithm> using namespace std; const int MAX_P = 2048; int r[MAX_P]; int main() { ios_base::sync_with_stdio(0); int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> r[i]; } sort(r, r + n, greater<int>()); while (k < n && r[k] == r[k - 1]) { ++k; } cout << k << endl; return 0; } |