C++ || BINARY SEARCH , PREFIX SUM SOLUTION
\nclass Solution {\npublic:\n    bool solve(int mid,vector<long long>&pref,vector<int>& nums, long long k){\n        for(int i=0,j=0;i<nums.size();i++){\n      
```\nclass Solution {\npublic:\n    bool solve(int mid,vector<long long>&pref,vector<int>& nums, long long k){\n        for(int i=0,j=0;i<nums.size();i++){\n            if((i-j+1)== mid){\n                int med=(i+j)/2;\n                \n                long long left=pref[med]-pref[j]+nums[j];\n                long long cntl=med-j+1;\n                long long right=pref[i]-pref[med]+nums[med];\n                long long cntr=i-med+1;\n                \n                long long sum=nums[med]*cntl - left + right- nums[med]*cntr;\n                if(sum<=k) return true;\n                j++;\n            }\n        }\n        return false;\n    }\n    int maxFrequencyScore(vector<int>& nums, long long k) {\n        sort(nums.begin(),nums.end());\n        int n=nums.size();\n        int lo=0,hi=n;\n        int ans=1;\n        \n        vector<long long>pref(n);\n        pref[0]=nums[0];\n        for(int i=1;i<n;i++) pref[i]=pref[i-1]+nums[i];\n        \n        while(lo<=hi){\n            int mid=lo+(hi-lo)/2;\n            if(solve(mid,pref,nums,k)){\n                ans=mid;\n                lo=mid+1;\n            }\n            else hi=mid-1;\n        }\n        return ans;\n    }\n};\n```
['Binary Search', 'C', 'Prefix Sum']