#include <bits/stdc++.h> using namespace std; #ifdef D #define DEBUG(x) \ do { \ x \ cout.flush(); \ } while (0) #else #define DEBUG(x) #endif const int MAXN = 2007; int n, k, a, ans; int t[127]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a; t[a]++; } for (int i = 120; i >= 0 && k > 0; i--) { ans += t[i]; k -= t[i]; } cout << ans; 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 | #include <bits/stdc++.h> using namespace std; #ifdef D #define DEBUG(x) \ do { \ x \ cout.flush(); \ } while (0) #else #define DEBUG(x) #endif const int MAXN = 2007; int n, k, a, ans; int t[127]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a; t[a]++; } for (int i = 120; i >= 0 && k > 0; i--) { ans += t[i]; k -= t[i]; } cout << ans; return 0; } |