#include <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define mp make_pair #define fi first #define se second #define PII pair<int,int> int n, k, a, c; int reps[121]; vi v; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a; if (!reps[a]) v.push_back(a); reps[a]++; } sort(v.begin(),v.end(), greater<>()); for (auto el : v) { c += reps[el]; if (c >= k) break; } cout << c; }
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 <bits/stdc++.h> using namespace std; #define pb push_back #define ll long long #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define mp make_pair #define fi first #define se second #define PII pair<int,int> int n, k, a, c; int reps[121]; vi v; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; for (int i = 0; i < n; ++i) { cin >> a; if (!reps[a]) v.push_back(a); reps[a]++; } sort(v.begin(),v.end(), greater<>()); for (auto el : v) { c += reps[el]; if (c >= k) break; } cout << c; } |