#include <iostream> #include<algorithm> using namespace std; //arrays int tab[2005]; int main() { int u; int k; int j = 0; cin >> u >> k; for (int i = 0; i < u; i++) { cin >> tab[i]; } sort(tab, tab + u, greater<>()); while (j < k) { j++; } while (tab[j - 1] == tab[j]) { j++; } cout << j; }
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 28 29 30 31 32 33 34 35 | #include <iostream> #include<algorithm> using namespace std; //arrays int tab[2005]; int main() { int u; int k; int j = 0; cin >> u >> k; for (int i = 0; i < u; i++) { cin >> tab[i]; } sort(tab, tab + u, greater<>()); while (j < k) { j++; } while (tab[j - 1] == tab[j]) { j++; } cout << j; } |