C++ solution using Sliding window
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```\n#define ll long long\nclass Solution {\npublic:\n    int maxFrequencyScore(vector<int>& nums, long long k) {\n        int n = nums.size();\n        sort(nums.begin(),nums.end());\n        long long sum = 0;\n        int ans = 0;\n        int i=0,j=0,idx=0;\n        for(;j<n;j++){\n\n            // adjustment of beech ka value\n            int ii = (j+i)/2;\n            if(ii == idx){\n                sum += (nums[j]-nums[idx]);\n            }\n            else {\n                ll gap = nums[ii] - nums[idx];\n                sum += ((idx-i+1)*gap);\n                sum -= ((j-ii)*gap);\n                sum += (nums[j] - nums[ii]);\n\n                idx = ii;\n            }\n\n            // updation part\n            if(sum <= k) {\n                ans = max(ans,j-i+1);\n            }\n            else { // removal of ith index wala part\n               while(sum > k){\n                   // removing ith\n                   sum -= (nums[idx] - nums[i]);\n                   i++;\n                   ii = (i+j)/2;\n                   if(ii == idx) {}\n                   else {\n                       ll gap = nums[ii]-nums[idx];\n                       sum += ((ii-i)*gap);\n                       sum -= ((j-idx)*gap);\n                       idx = ii;\n                   }\n                   ans = max(ans,j-i+1);\n               }\n            }\n\n        }\n\n        return ans;\n    }\n};\n```
['C++']