/*#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops")*/ #include <bits/stdc++.h> #define bit(n, i) (((n)>>(i))&1) #define cat(x) cout << #x << " = " << x << "\n" #define pb push_back #define mp make_pair #define se second #define fi first #define inf 2000000000 #define llinf 2000000000000000000LL #define forn(i, a, b) for(ll i = (a); i <= (b); ++i) #define all(x) (x).begin(), (x).end() #define ppc(x) __builtin_popcount(x) using namespace std; typedef long long ll; typedef double ld; typedef pair<int, int> i2; typedef vector<int> vi; typedef vector<ll> vll; int cnt[129]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; for(int i = 1; i <= n; ++i) { int a; cin >> a; cnt[a]++; } int res = 0; for(int i = 120; i >= 1; --i) { if(k > 0) { k -= cnt[i]; res += cnt[i]; } } cout << res; 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 36 37 38 39 40 41 42 43 44 45 | /*#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops")*/ #include <bits/stdc++.h> #define bit(n, i) (((n)>>(i))&1) #define cat(x) cout << #x << " = " << x << "\n" #define pb push_back #define mp make_pair #define se second #define fi first #define inf 2000000000 #define llinf 2000000000000000000LL #define forn(i, a, b) for(ll i = (a); i <= (b); ++i) #define all(x) (x).begin(), (x).end() #define ppc(x) __builtin_popcount(x) using namespace std; typedef long long ll; typedef double ld; typedef pair<int, int> i2; typedef vector<int> vi; typedef vector<ll> vll; int cnt[129]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; for(int i = 1; i <= n; ++i) { int a; cin >> a; cnt[a]++; } int res = 0; for(int i = 120; i >= 1; --i) { if(k > 0) { k -= cnt[i]; res += cnt[i]; } } cout << res; return 0; } |