#include <iostream> #include <algorithm> #define rep(a,b) for(int a=0; a<(b); ++a) #define nl "\n" using namespace std; int n,k,buckets[127]; int main() { cin>>n>>k; rep(i,n){ int buf; cin>>buf; buckets[buf]++; } int i=120; int res=0; while(res<k){ res+=buckets[i]; --i; } cout<<res<<nl; 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 | #include <iostream> #include <algorithm> #define rep(a,b) for(int a=0; a<(b); ++a) #define nl "\n" using namespace std; int n,k,buckets[127]; int main() { cin>>n>>k; rep(i,n){ int buf; cin>>buf; buckets[buf]++; } int i=120; int res=0; while(res<k){ res+=buckets[i]; --i; } cout<<res<<nl; return 0; } |