#include <iostream> using namespace std; int compare (const void * a, const void * b) { return ( *(int*)b - *(int*)a ); } int main() { int n, k, a[2001]; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } qsort(a, n, sizeof(int), compare); int last = a[k-1]; for (int i = k; i <= n; i++) { if (a[i] != last) { cout << i << endl; return 0; } } 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 | #include <iostream> using namespace std; int compare (const void * a, const void * b) { return ( *(int*)b - *(int*)a ); } int main() { int n, k, a[2001]; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; } qsort(a, n, sizeof(int), compare); int last = a[k-1]; for (int i = k; i <= n; i++) { if (a[i] != last) { cout << i << endl; return 0; } } return 0; } |