#include <bits/stdc++.h> using namespace std; vector<int>t; int n,k,a,w; int main() { cin>>n>>k; for(int i=0; i<n; i++) { cin>>a; t.push_back(a); } sort(t.begin(),t.end()); //cout<<t[0]<<"\n"; a=n-1; while(t[a]>=t[n-k]) { //cout<<t[a]<<"\n"; w++; a--; } cout<<w<<"\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <bits/stdc++.h> using namespace std; vector<int>t; int n,k,a,w; int main() { cin>>n>>k; for(int i=0; i<n; i++) { cin>>a; t.push_back(a); } sort(t.begin(),t.end()); //cout<<t[0]<<"\n"; a=n-1; while(t[a]>=t[n-k]) { //cout<<t[a]<<"\n"; w++; a--; } cout<<w<<"\n"; } |