jai shree ram
class Solution {\n    public:\n        \n        bool pos(vector &nums,vector &pref,long long mid,long long k)\n        {\n            int l=0,h=mid-1;\n       
class Solution {\n    public:\n        \n        bool pos(vector<int> &nums,vector<long long> &pref,long long mid,long long k)\n        {\n            int l=0,h=mid-1;\n            \n            int n=nums.size();\n            \n            while(h<n)\n            {\n                int x=(l+h)/2;\n                long long req=0;\n                \n                long long a=(x-l+1);\n                a*=nums[x];\n                \n                long long b=(pref[x]-((l-1>=0)?pref[l-1]:0));\n                \n                \n                long long c=(pref[h]-((x-1>=0)?pref[x-1]:0));\n                long long d=(h-x+1);\n                d*=nums[x];\n                \n                req=a-b+c-d;\n                \n                if(req<=k)\n                    return true;\n                \n                l++;\n                h++;\n            }\n            return false;\n        }\n        \n        int maxFrequencyScore(vector<int>& nums, long long k) \n        {\n            int n=nums.size();\n            int l=1,h=n;\n            \n            sort(nums.begin(),nums.end());\n            \n            vector<long long> pref(n);\n            pref[0]=nums[0];\n            \n            \n            for(int i=1;i<n;i++)\n                pref[i]=nums[i]+pref[i-1];\n            \n            \n            int ans=1;\n            \n            while(l<=h)\n            {\n                long long mid=(l+h);\n                mid/=2;\n                \n                bool is=pos(nums,pref,mid,k);\n                if(is)\n                {\n                    ans=mid;\n                    l=mid+1;\n                }\n                else\n                    h=mid-1;\n            }\n            return ans;\n        }\n    };
['C++']