#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, k;
vector<int> as;
int main()
{
cin >> n >> k;
as.resize(n);
for(int x=0;x<n;x++){
cin >> as[x];
}
sort(as.begin(), as.end());
reverse(as.begin(), as.end());
int last = as[k-1];
int result = k;
while (result < n && as[result] == last)
{
result++;
}
cout << result << '\n';
}
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 26 27 28 29 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int n, k; vector<int> as; int main() { cin >> n >> k; as.resize(n); for(int x=0;x<n;x++){ cin >> as[x]; } sort(as.begin(), as.end()); reverse(as.begin(), as.end()); int last = as[k-1]; int result = k; while (result < n && as[result] == last) { result++; } cout << result << '\n'; } |
English