#include <cstdio> #include <cstdint> #include <vector> #include <algorithm> using namespace std; int main() { unsigned short n; short k; scanf("%hu %hu", &n, &k); vector<uint8_t> a(n); for (uint8_t& c : a) scanf(" %hhu", &c); sort(a.begin(), a.end(), greater<uint8_t>()); uint8_t p = a[0]; for (unsigned short i = 0; ; ++i) { if (i < k || a[i] == p) p = a[i]; else { printf("%hu", i); break; } } 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 | #include <cstdio> #include <cstdint> #include <vector> #include <algorithm> using namespace std; int main() { unsigned short n; short k; scanf("%hu %hu", &n, &k); vector<uint8_t> a(n); for (uint8_t& c : a) scanf(" %hhu", &c); sort(a.begin(), a.end(), greater<uint8_t>()); uint8_t p = a[0]; for (unsigned short i = 0; ; ++i) { if (i < k || a[i] == p) p = a[i]; else { printf("%hu", i); break; } } return 0; } |