// Szymon Rusiecki
#include <bits/stdc++.h>
bool order (int A, int B) {
return A > B;
}
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int n, k;
std::cin >> n >> k;
int *tab = new int [n];
for (int i = 0; i < n; ++i)
std::cin >> tab[i];
std::sort(tab, tab + n, order);
int output = 1;
--k;
for (int i = 1; i < n; ++i) {
if (tab[i] == tab[i - 1]) {
++output;
--k;
}
else {
if (k > 0) {
++output;
--k;
}
else break;
}
}
std::cout << output;
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | // Szymon Rusiecki #include <bits/stdc++.h> bool order (int A, int B) { return A > B; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); int n, k; std::cin >> n >> k; int *tab = new int [n]; for (int i = 0; i < n; ++i) std::cin >> tab[i]; std::sort(tab, tab + n, order); int output = 1; --k; for (int i = 1; i < n; ++i) { if (tab[i] == tab[i - 1]) { ++output; --k; } else { if (k > 0) { ++output; --k; } else break; } } std::cout << output; return 0; } |
English