#include <iostream> #include <array> int main() { int n; int k; constexpr int MAX_RESULT = 120; std::array<int, MAX_RESULT + 1> counts{0}; std::cin >> n >> k; for(int i = 0 ; i < n; ++i) { int a = 0; std::cin >> a; // Count the number of each actual result achieved ++counts[a]; } int negExtra = k; // Give away the t-shirts starting form top ranks for(int i = MAX_RESULT; negExtra > 0 && i >= 0; --i) { negExtra -= counts[i]; } std::cout << k - negExtra << std::endl; }
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 | #include <iostream> #include <array> int main() { int n; int k; constexpr int MAX_RESULT = 120; std::array<int, MAX_RESULT + 1> counts{0}; std::cin >> n >> k; for(int i = 0 ; i < n; ++i) { int a = 0; std::cin >> a; // Count the number of each actual result achieved ++counts[a]; } int negExtra = k; // Give away the t-shirts starting form top ranks for(int i = MAX_RESULT; negExtra > 0 && i >= 0; --i) { negExtra -= counts[i]; } std::cout << k - negExtra << std::endl; } |