#include <iostream> using namespace std; #define MAX 200 int v[MAX+1]; int main() { int n,k,a,r = 0, i = MAX; cin >> n >> k; while(n--) { cin >> a; v[a]++; } while(r<k) r+=v[i--]; cout << r << "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include <iostream> using namespace std; #define MAX 200 int v[MAX+1]; int main() { int n,k,a,r = 0, i = MAX; cin >> n >> k; while(n--) { cin >> a; v[a]++; } while(r<k) r+=v[i--]; cout << r << "\n"; } |