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