////Krzysztof Pieprzak
#include <bits/stdc++.h>
using namespace std;
int t[5000];
int main() {
int n, k;
scanf("%d %d", &n, &k);
for(int i=0; i<n; i++)
scanf ("%d", &t[i]);
sort(t, t+n);
int last = -1;
int res = 0;
for(; res<n; res++) {
if (res >= k && last != t[n - res -1])
break;
last = t[n - res - 1];
}
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 | ////Krzysztof Pieprzak #include <bits/stdc++.h> using namespace std; int t[5000]; int main() { int n, k; scanf("%d %d", &n, &k); for(int i=0; i<n; i++) scanf ("%d", &t[i]); sort(t, t+n); int last = -1; int res = 0; for(; res<n; res++) { if (res >= k && last != t[n - res -1]) break; last = t[n - res - 1]; } printf("%d\n", res); return 0; } |
English