#include <iostream> #include <vector> #include <functional> #include <climits> using namespace std; int main() { int n; cin>>n; int k; cin>>k; vector<int> a(n); for(auto &x : a) cin>>x; sort(a.begin(), a.end(), greater<int>()); int i; for(i=k-1; i<n; i++) if(i==n-1||a[i]!=a[i+1]) break; cout<<i+1; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <iostream> #include <vector> #include <functional> #include <climits> using namespace std; int main() { int n; cin>>n; int k; cin>>k; vector<int> a(n); for(auto &x : a) cin>>x; sort(a.begin(), a.end(), greater<int>()); int i; for(i=k-1; i<n; i++) if(i==n-1||a[i]!=a[i+1]) break; cout<<i+1; return 0; } |