#include<cstdio> #include<algorithm> using namespace std; int u[2000]; int main() { int n, k; scanf("%d %d", &n, &k); for(int i = 0; i < n; i++) { scanf("%d", &u[i]); } sort(u, u + n, greater<int>()); int gr = u[k-1]; int more = 0; for(int i = k; i < n; i++) { if(u[i] != gr) break; more++; } printf("%d", k + more); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include<cstdio> #include<algorithm> using namespace std; int u[2000]; int main() { int n, k; scanf("%d %d", &n, &k); for(int i = 0; i < n; i++) { scanf("%d", &u[i]); } sort(u, u + n, greater<int>()); int gr = u[k-1]; int more = 0; for(int i = k; i < n; i++) { if(u[i] != gr) break; more++; } printf("%d", k + more); } |