#include <bits/stdc++.h>
int main(){
int a[120] = { 0 };
int n,k;
std::cin >> n >> k;
for(int i = 0; i < n; i++){
int points;
std::cin >> points;
a[points-1]++;
}
int current_sum = 0;
for(int i = 119; i >= 0; i--){
current_sum += a[i];
if(current_sum >= k){
std::cout << current_sum << std::endl;
return 0;
}
}
std::cout << k << std::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 32 33 34 35 36 37 | #include <bits/stdc++.h> int main(){ int a[120] = { 0 }; int n,k; std::cin >> n >> k; for(int i = 0; i < n; i++){ int points; std::cin >> points; a[points-1]++; } int current_sum = 0; for(int i = 119; i >= 0; i--){ current_sum += a[i]; if(current_sum >= k){ std::cout << current_sum << std::endl; return 0; } } std::cout << k << std::endl; } |
English