#include <iostream> #include <vector> #include <algorithm> int main() { std::ios_base::sync_with_stdio(0); int n, k; std::cin >> n >> k; // more t-shirts than participants if (k >= n) { std::cout << n << '\n'; return 0; } std::vector<int> points; points.resize(n); int a; for (int i = 0; i < n; i++) { std::cin >> a; points[i] = a; } std::sort(points.begin(), points.end()); // for(int e : points){ // std::cout << e << ','; // } // std::cout << '\n'; auto bound = points.end() - k; auto limit = std::lower_bound(points.begin(), points.end(), *bound); std::cout << std::distance(limit, points.end()) << '\n'; }
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 | #include <iostream> #include <vector> #include <algorithm> int main() { std::ios_base::sync_with_stdio(0); int n, k; std::cin >> n >> k; // more t-shirts than participants if (k >= n) { std::cout << n << '\n'; return 0; } std::vector<int> points; points.resize(n); int a; for (int i = 0; i < n; i++) { std::cin >> a; points[i] = a; } std::sort(points.begin(), points.end()); // for(int e : points){ // std::cout << e << ','; // } // std::cout << '\n'; auto bound = points.end() - k; auto limit = std::lower_bound(points.begin(), points.end(), *bound); std::cout << std::distance(limit, points.end()) << '\n'; } |