#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n, k, wynik=0;
cin>>n>>k;
int t[n];
for(int i=0; i<n; ++i)
cin>>t[i];
sort(t, t+n);
for(int i=n-k; i>0; --i)
{if(t[i]==t[i-1])
wynik++;
else break;}
cout<<k+wynik;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <iostream> #include <algorithm> using namespace std; int main() { int n, k, wynik=0; cin>>n>>k; int t[n]; for(int i=0; i<n; ++i) cin>>t[i]; sort(t, t+n); for(int i=n-k; i>0; --i) {if(t[i]==t[i-1]) wynik++; else break;} cout<<k+wynik; return 0; } |
English