#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
bool myfunction (int i,int j) { return i>j; }
int main() {
short n, k;
scanf("%hu%hu", &n, &k);
if (k == n) {
printf("%d", k);
return 0;
}
std::vector<short> v(n);
for(int i=0; i<n; i++) {
scanf("%hu", &v[i]);
}
std::sort (v.begin(), v.end(), myfunction);
k--;
while (v[k] == v[k + 1] && k < n) k++;
printf("%d", k + 1);
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 26 27 28 | #include <algorithm> #include <cstdio> #include <vector> using namespace std; bool myfunction (int i,int j) { return i>j; } int main() { short n, k; scanf("%hu%hu", &n, &k); if (k == n) { printf("%d", k); return 0; } std::vector<short> v(n); for(int i=0; i<n; i++) { scanf("%hu", &v[i]); } std::sort (v.begin(), v.end(), myfunction); k--; while (v[k] == v[k + 1] && k < n) k++; printf("%d", k + 1); return 0; } |
English