#include <iostream> #include <algorithm> using namespace std; const int MAX = 2005; int a[MAX]; int main() { int n, k; cin >> n >> k; for(int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a+n); reverse(a, a+n); int ct = k; while(a[ct-1] == a[ct]) ++ct; cout << ct << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <iostream> #include <algorithm> using namespace std; const int MAX = 2005; int a[MAX]; int main() { int n, k; cin >> n >> k; for(int i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a+n); reverse(a, a+n); int ct = k; while(a[ct-1] == a[ct]) ++ct; cout << ct << endl; } |