Very easy solution using sorting
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int maxFrequencyScore(vector<int>& nums, long long k) {\n       sort(nums.begin(),nums.end());\n       int n=nums.size();\n       vector<long long>prefixSum(n+1,0);\n       for(int i=0; i<n; i++) {\n           prefixSum[i+1]=prefixSum[i]+nums[i];\n\n       }\n       int start=0;\n       int end=1;\n       int maxScore=1;\n       while(end<n) {\n           end++;\n           int mid=(start+end)/2;\n           long long target=nums[mid];\n           long long cost=(target*(mid-start)-(prefixSum[mid]-prefixSum[start]))+(prefixSum[end]-prefixSum[mid]-target*(end-mid));\n           while(start<end && cost>k) {\n               start++;\n               mid=(start+end)/2;\n               target=nums[mid];\n               cost=(target*(mid-start)-(prefixSum[mid]-prefixSum[start]))+(prefixSum[end]-prefixSum[mid]-target*(end-mid));\n\n           }\n           maxScore=max(maxScore,end-start);\n       }\n       return maxScore;\n        \n    }\n};\n```
['Sorting', 'Prefix Sum', 'C++']