#include <algorithm> #include <iostream> using namespace std; int main() { int n, k, shirtTreeshold; cin >> n >> k; int scores[n]; for (int i = 0; i < n; i++) cin >> scores[i]; sort(scores, scores + n, greater<int>()); shirtTreeshold = scores[k - 1]; while (scores[k] == shirtTreeshold && k < n) k++; cout << k; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <algorithm> #include <iostream> using namespace std; int main() { int n, k, shirtTreeshold; cin >> n >> k; int scores[n]; for (int i = 0; i < n; i++) cin >> scores[i]; sort(scores, scores + n, greater<int>()); shirtTreeshold = scores[k - 1]; while (scores[k] == shirtTreeshold && k < n) k++; cout << k; return 0; } |