#include <iostream> #include <vector> #include <algorithm> using namespace std; bool cmp_greater(const int& a, const int& b) { return a>b; } int main() { int n,k; cin>>n>>k; vector<int> punkty(n,0); for (int ii=0; ii<n; ii++) { int temp; cin>>temp; punkty[ii]=temp; } sort(punkty.begin(), punkty.end(), cmp_greater); int minPunkty = punkty[k-1]; auto it = upper_bound(punkty.begin()+k, punkty.end(), minPunkty, cmp_greater); cout<<int(it-punkty.begin())<<endl; 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 27 28 29 30 31 32 | #include <iostream> #include <vector> #include <algorithm> using namespace std; bool cmp_greater(const int& a, const int& b) { return a>b; } int main() { int n,k; cin>>n>>k; vector<int> punkty(n,0); for (int ii=0; ii<n; ii++) { int temp; cin>>temp; punkty[ii]=temp; } sort(punkty.begin(), punkty.end(), cmp_greater); int minPunkty = punkty[k-1]; auto it = upper_bound(punkty.begin()+k, punkty.end(), minPunkty, cmp_greater); cout<<int(it-punkty.begin())<<endl; return 0; } |