#include <iostream> const int N = 2000; int points[120]; int main() { int n,k,score; std::cin >> n; std::cin >> k; for(int i = 0; i < 120; ++i) { points[i] = 0; } for(int i = 0; i < n; ++i) { std::cin >> score; points[score - 1]++; } int ret = 0; int iter = 119; while(ret < k) { ret += points[iter--]; } std::cout << ret; }
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 | #include <iostream> const int N = 2000; int points[120]; int main() { int n,k,score; std::cin >> n; std::cin >> k; for(int i = 0; i < 120; ++i) { points[i] = 0; } for(int i = 0; i < n; ++i) { std::cin >> score; points[score - 1]++; } int ret = 0; int iter = 119; while(ret < k) { ret += points[iter--]; } std::cout << ret; } |