#include <bits/stdc++.h> using namespace std; int t[20005],ans,k,n; int main(){ cin>>n>>k; for(int i=1; i<=n; i++){ cin>>t[i]; } sort(t+1,t+n+1); for(int i=n-k; i>=1; i--){ if(t[i]==t[i+1]) ans++; else break; } cout<<ans+k; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <bits/stdc++.h> using namespace std; int t[20005],ans,k,n; int main(){ cin>>n>>k; for(int i=1; i<=n; i++){ cin>>t[i]; } sort(t+1,t+n+1); for(int i=n-k; i>=1; i--){ if(t[i]==t[i+1]) ans++; else break; } cout<<ans+k; } |