#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> Q;
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n,k,x;
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>x;
Q.push_back(x*-1);
}
sort(Q.begin(),Q.end());
Q.push_back(1000);
int wynik=0;
for(int i=0;i<n;i++)
{
Q[i]*=-1;
if(wynik<k)
{
wynik++;
}
else if(wynik>=k && Q[i]==Q[i-1])
wynik++;
else break;
}
cout<<wynik;
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 33 34 | #include<iostream> #include<vector> #include<algorithm> using namespace std; vector<int> Q; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n,k,x; cin>>n>>k; for(int i=1;i<=n;i++) { cin>>x; Q.push_back(x*-1); } sort(Q.begin(),Q.end()); Q.push_back(1000); int wynik=0; for(int i=0;i<n;i++) { Q[i]*=-1; if(wynik<k) { wynik++; } else if(wynik>=k && Q[i]==Q[i-1]) wynik++; else break; } cout<<wynik; return 0; } |
English