#include <bits/stdc++.h> using namespace std; int n, k, a[2005], cnt[125]; int32_t main() { ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; cnt[a[i]]++; } int tshirts = 0; for (int i = 120; i >= 0; i--) { tshirts += cnt[i]; if (tshirts >= k) { cout << tshirts << "\n"; return 0; } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <bits/stdc++.h> using namespace std; int n, k, a[2005], cnt[125]; int32_t main() { ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; cnt[a[i]]++; } int tshirts = 0; for (int i = 120; i >= 0; i--) { tshirts += cnt[i]; if (tshirts >= k) { cout << tshirts << "\n"; return 0; } } } |