#include <vector>
#include <iostream>
#include <algorithm>
int main() {
int16_t participants{};
int16_t shirts{};
std::cin >> participants >> shirts;
std::vector<int8_t> points(participants);
for (int i = 0; i < participants; ++i) {
int temp;
std::cin >> temp;
points[i] = temp;
}
std::sort(points.begin(), points.end(), std::greater<int8_t>{});
const auto additional_shirts = std::count(points.cbegin() + shirts, points.cend(), points[shirts - 1]);
std::cout << shirts + additional_shirts << "\n";
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <vector> #include <iostream> #include <algorithm> int main() { int16_t participants{}; int16_t shirts{}; std::cin >> participants >> shirts; std::vector<int8_t> points(participants); for (int i = 0; i < participants; ++i) { int temp; std::cin >> temp; points[i] = temp; } std::sort(points.begin(), points.end(), std::greater<int8_t>{}); const auto additional_shirts = std::count(points.cbegin() + shirts, points.cend(), points[shirts - 1]); std::cout << shirts + additional_shirts << "\n"; return 0; } |
English