#include <iostream> #include <algorithm> #define MAX 2009 using namespace std; int values[MAX]; int main() { int n, k; cin >> n >> k; for (int i=0; i<n; i++) { cin >> values[i]; } sort(values, values + n, greater<int>()); values[n] = -1; int current = k; while (values[k - 1] == values[current]) current++; cout << current; 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 | #include <iostream> #include <algorithm> #define MAX 2009 using namespace std; int values[MAX]; int main() { int n, k; cin >> n >> k; for (int i=0; i<n; i++) { cin >> values[i]; } sort(values, values + n, greater<int>()); values[n] = -1; int current = k; while (values[k - 1] == values[current]) current++; cout << current; return 0; } |