#include <iostream> #include <vector> #include <algorithm> using namespace std; bool desc(int i, int j) { return (j < i); } int main() { ios_base::sync_with_stdio(false); int a, n, k; cin >> n >> k; vector<int> nums; while (n-- > 0) { cin >> a; nums.push_back(a); } sort(nums.begin(), nums.end(), desc); int shirts = 0; int prev = -1; for (const auto &num: nums) { if (shirts >= k && prev != num) { break; } shirts += 1; prev = num; } cout << shirts; 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 | #include <iostream> #include <vector> #include <algorithm> using namespace std; bool desc(int i, int j) { return (j < i); } int main() { ios_base::sync_with_stdio(false); int a, n, k; cin >> n >> k; vector<int> nums; while (n-- > 0) { cin >> a; nums.push_back(a); } sort(nums.begin(), nums.end(), desc); int shirts = 0; int prev = -1; for (const auto &num: nums) { if (shirts >= k && prev != num) { break; } shirts += 1; prev = num; } cout << shirts; return 0; } |