#include <string> #include <iostream> #include <algorithm> using namespace std; int main(int argc, char const *argv[]) { int n, k; int arr[2001]; cin >> n >> k; int result = k; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n, greater<int>()); while (result < n && arr[result - 1] == arr[result]) { result++; } cout << result << endl; 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 | #include <string> #include <iostream> #include <algorithm> using namespace std; int main(int argc, char const *argv[]) { int n, k; int arr[2001]; cin >> n >> k; int result = k; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n, greater<int>()); while (result < n && arr[result - 1] == arr[result]) { result++; } cout << result << endl; return 0; } |