#include <iostream>
#include <algorithm>
#define REP(x,n) for(int x=0;x<(n);++x)
#define FOREACH(x,n) for(__typeof(n.begin()) x = (n).begin(); x != (n).end(); ++x)
using namespace std;
const int MAX_N = 2001;
int tab[MAX_N];
int n,k;
int main() {
ios_base::sync_with_stdio(0);
cin>>n>>k;
REP(x,n)
cin>>tab[x];
std::sort(tab, tab+n, std::greater<int>());
// REP(x,n)
// cout<<tab[x]<<" ";
// cout<<endl;
auto iter = upper_bound(tab, tab+n, tab[k-1], std::greater<int>());
cout << (iter-tab) << endl;
// cout << " " << *iter << 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 | #include <iostream> #include <algorithm> #define REP(x,n) for(int x=0;x<(n);++x) #define FOREACH(x,n) for(__typeof(n.begin()) x = (n).begin(); x != (n).end(); ++x) using namespace std; const int MAX_N = 2001; int tab[MAX_N]; int n,k; int main() { ios_base::sync_with_stdio(0); cin>>n>>k; REP(x,n) cin>>tab[x]; std::sort(tab, tab+n, std::greater<int>()); // REP(x,n) // cout<<tab[x]<<" "; // cout<<endl; auto iter = upper_bound(tab, tab+n, tab[k-1], std::greater<int>()); cout << (iter-tab) << endl; // cout << " " << *iter << endl; return 0; } |
English