#include<iostream> #include<algorithm> using namespace std; int main(){ int n,k; cin >>n>>k; int *tab = new int[n+1]; for(int i=0 ;i<n;i++) cin >>tab[i]; sort(tab,tab+n,greater<int>()); int ile =k; for (int i=k;i<n;i++){ if (tab[k-1] == tab[i]) ile++; } cout <<ile; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include<iostream> #include<algorithm> using namespace std; int main(){ int n,k; cin >>n>>k; int *tab = new int[n+1]; for(int i=0 ;i<n;i++) cin >>tab[i]; sort(tab,tab+n,greater<int>()); int ile =k; for (int i=k;i<n;i++){ if (tab[k-1] == tab[i]) ile++; } cout <<ile; return 0; } |