#include <iostream> #include <vector> #include <algorithm> using namespace std; bool comp(int a, int b) { return a > b; } int main(){ int n, k; vector<int> a; cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end(), comp); k--; int ans = k; for (int i = k; i < n - 1; i++) if (a[i] == a[i + 1]) ans++; else break; cout << ans + 1; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; bool comp(int a, int b) { return a > b; } int main(){ int n, k; vector<int> a; cin >> n >> k; a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end(), comp); k--; int ans = k; for (int i = k; i < n - 1; i++) if (a[i] == a[i + 1]) ans++; else break; cout << ans + 1; return 0; } |