#include <bits/stdc++.h> using namespace std; int main(){ int n, k, a, counter = 0; cin >> n >> k; int arr[n]; for(int i = 0; i < n; i++){ cin >> arr[i]; } sort(arr, arr + n, greater<int>()); for(int i = 0; i < k; i++){ counter++; } a = k; while(arr[a] == arr[a - 1]){ counter++; a++; } cout << counter << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <bits/stdc++.h> using namespace std; int main(){ int n, k, a, counter = 0; cin >> n >> k; int arr[n]; for(int i = 0; i < n; i++){ cin >> arr[i]; } sort(arr, arr + n, greater<int>()); for(int i = 0; i < k; i++){ counter++; } a = k; while(arr[a] == arr[a - 1]){ counter++; a++; } cout << counter << endl; } |