#include <iostream> #include <algorithm> using namespace std; int n, k ,t[100000]; int main() { cin>>n>>k; for (int i=0; i<n; i++) { cin>>t[i]; } sort(t, t+n); while(t[n-k]==t[n-k-1]) { k++; } if(k==1) cout<<1; else cout<<k; 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 | #include <iostream> #include <algorithm> using namespace std; int n, k ,t[100000]; int main() { cin>>n>>k; for (int i=0; i<n; i++) { cin>>t[i]; } sort(t, t+n); while(t[n-k]==t[n-k-1]) { k++; } if(k==1) cout<<1; else cout<<k; return 0; } |