#include<cstdio> #include<algorithm> #include<vector> using namespace std; #define INF 100000 int n,k,a; vector<int> ranking; #define MIN(_a,_b) (_a)<(_b)?(_a):(_b) int main() { scanf("%d %d", &n, &k); for(int i=0;i<n;i++) { scanf("%d", &a); ranking.push_back(a); } sort(ranking.begin(), ranking.end()); int last = ranking[n-k]; int res = k; for(int i=n-k-1;i>=0;i--) { if(ranking[i]==last) { res++; } else { break; } } printf("%d\n", res); 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<cstdio> #include<algorithm> #include<vector> using namespace std; #define INF 100000 int n,k,a; vector<int> ranking; #define MIN(_a,_b) (_a)<(_b)?(_a):(_b) int main() { scanf("%d %d", &n, &k); for(int i=0;i<n;i++) { scanf("%d", &a); ranking.push_back(a); } sort(ranking.begin(), ranking.end()); int last = ranking[n-k]; int res = k; for(int i=n-k-1;i>=0;i--) { if(ranking[i]==last) { res++; } else { break; } } printf("%d\n", res); return 0; } |