#include <bits/stdc++.h> using namespace std; const int N = 2003; int tab[N]; int main(){ int n, k; cin >> n >> k; for (int i = 0; i < n; i ++) { cin >> tab[i]; tab[i] *= -1; } sort(tab, tab + n); while (k < n && tab[k] == tab[k - 1]) k ++; cout << k << "\n"; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <bits/stdc++.h> using namespace std; const int N = 2003; int tab[N]; int main(){ int n, k; cin >> n >> k; for (int i = 0; i < n; i ++) { cin >> tab[i]; tab[i] *= -1; } sort(tab, tab + n); while (k < n && tab[k] == tab[k - 1]) k ++; cout << k << "\n"; return 0; } |