#include <bits/stdc++.h> const int MAXN = 1000005; int t[MAXN]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i=0; i<n; i++) { scanf("%d", &t[i]); t[i] = -t[i]; } std::sort(t, t+n); int l = k; for (int i=k+1; i<=n; i++) { if (t[i-1] == t[k-1]) l = i; } printf("%d\n", l); 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 | #include <bits/stdc++.h> const int MAXN = 1000005; int t[MAXN]; int main() { int n, k; scanf("%d%d", &n, &k); for (int i=0; i<n; i++) { scanf("%d", &t[i]); t[i] = -t[i]; } std::sort(t, t+n); int l = k; for (int i=k+1; i<=n; i++) { if (t[i-1] == t[k-1]) l = i; } printf("%d\n", l); return 0; } |