simple and easy to understand
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    typedef long long ll;\n    int maxFrequencyScore(vector<int>& a, long long k) {\n        sort(a.begin(),a.end());\n\n        int n=a.size(),s=0,e=n,ans=1;\n        vector<ll> pre(n,0);\n        pre[0]=a[0];\n        for(int i=1;i<n;i++)pre[i]=pre[i-1]+a[i];\n\n        while(s<=e){\n            int mid=(s+e)/2;\n            bool chk=0;\n            for(int i=0,j=0;j<n;j++){\n                if(j-i+1==mid){\n                    int m=(i+j)/2;\n                    ll x=pre[m]-pre[i]+a[i],xl=m-i+1;\n                    ll y=pre[j]-pre[m]+a[m],yl=j-m+1;\n                    long long p=abs(x-a[m]*xl)+abs(y-a[m]*yl);\n                    if(p<=k){\n                        chk=1;\n                        break;\n                    }\n                    i++;\n                }\n            }\n            if(chk)ans=mid,s=mid+1;\n            else e=mid-1;\n        }\n\n        return ans;\n    }\n};\n```
['C++']