#include <iostream> using namespace std; const int maxScore = 120; int count[maxScore + 3]; int main() { int n, k; cin >> n >> k; int a; for (int i = 0; i < n; i++) { cin >> a; count[a]++; } // for(int i=0; i<=120; i++){ // if(count[i] != 0) // cout<<i<<": "<<count[i]<<"\n"; // } int sum = 0; int i = maxScore; while (sum < k) { sum += count[i]; i--; } cout << sum << "\n"; }
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 <iostream> using namespace std; const int maxScore = 120; int count[maxScore + 3]; int main() { int n, k; cin >> n >> k; int a; for (int i = 0; i < n; i++) { cin >> a; count[a]++; } // for(int i=0; i<=120; i++){ // if(count[i] != 0) // cout<<i<<": "<<count[i]<<"\n"; // } int sum = 0; int i = maxScore; while (sum < k) { sum += count[i]; i--; } cout << sum << "\n"; } |