#include <iostream>
#include <vector>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
int t[121];
for(int i=0; i<121; i++) {
t[i] = 0;
}
for(int i=0; i<n; i++) {
int x;
cin >> x;
t[x]++;
}
int total = 0, idx = 120;
while(idx >= 0 && total < k) {
total += t[idx--];
}
cout << total << endl;
}
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 | #include <iostream> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int t[121]; for(int i=0; i<121; i++) { t[i] = 0; } for(int i=0; i<n; i++) { int x; cin >> x; t[x]++; } int total = 0, idx = 120; while(idx >= 0 && total < k) { total += t[idx--]; } cout << total << endl; } |
English