#include<bits/stdc++.h> using namespace std; int main(){ int n,k,i,a; vector <int> v; scanf("%d%d",&n,&k); for(i=0;i<n;i++){ scanf("%d",&a); v.push_back(a); } sort(v.begin(),v.end(),greater()); i=k-1; while(i+1<n && v[i]==v[i+1]) i++; printf("%d\n",i+1); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<bits/stdc++.h> using namespace std; int main(){ int n,k,i,a; vector <int> v; scanf("%d%d",&n,&k); for(i=0;i<n;i++){ scanf("%d",&a); v.push_back(a); } sort(v.begin(),v.end(),greater()); i=k-1; while(i+1<n && v[i]==v[i+1]) i++; printf("%d\n",i+1); return 0; } |