Source Code

#include <bits/stdc++.h>

using namespace std;
int arr[100001];
map <int,int>mp;
int main()
{
	int x,k,ans=0;
	cin>>x>>k;
	for(int i=0;i<x;i++){
		cin>>arr[i];
		mp [arr[i]]++;
	}
	sort(arr,arr+x);
	for(int i=0;i<100001;i++){
		if(!mp[i])break;
		if(k<mp[i]){
			ans+=k;
		}
		else ans+=mp[i];
	}
	cout<<ans;
	
	
	
			
    return 0;
}
Copy
Bitar The Handy Man fakher20
GNU G++17
14 ms
1.0 MB
Wrong Answer