Sliding Window Solution
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 int> pre(n+1,0);\n        for(int i=1;i<=n;i++)\n        {\n            pre[i]=pre[i-1]+nums[i-1];  \n        }\n        int l=0,r=0;\n        int maxi=0;\n        while(r<n)\n        {\n            int mid=(l+r)/2;\n            long long tk=k;\n            tk-=(1LL*nums[mid]*(mid-l)-(pre[mid]-pre[l]));\n            tk-=((pre[r+1]-pre[mid+1])-1LL*nums[mid]*(r-mid));\n            while(tk<0)\n            {\n             l++;\n             int mid=(l+r)/2;\n            tk=k;\n            tk-=(1ll*nums[mid]*(mid-l)-(pre[mid]-pre[l]));\n            tk-=((pre[r+1]-pre[mid+1])-1LL*nums[mid]*(r-mid));\n            }\n            if(r-l+1>maxi)\n            maxi=r-l+1;\n            r++;\n        }\n        return maxi;\n    }\n};\n```
['C++']