Prefix sum+binary search tofind left border
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```\npublic class Solution {\n    public int MaxFrequencyScore(int[] nums, long k) {\n        int n= nums.Length;\n      int ans=1;\n        Array.Sort(nums);\n        if (k==0){\n            int s=1;\n            for (int i=0; i<n; i+=s){\n                while(i+s<n && nums[i]==nums[i+s]){\n                    s++;\n                }\n                ans=Math.Max(ans,s);\n            }\n            return ans;\n        }\n       \n        Console.WriteLine();\n        long [] sum= new long [n+1];\n        for (int i=0; i<n;i++){\n            sum[i+1]= sum[i]+nums[i];\n        }\n       \n               for (int i=n; i>=ans; i--){\n            int r=i-1;\n            int l=1;\n            bool check=false;\n            while(l<=r){\n                int m=(r+l)/2;\n                int m1=(i+m)/2;\n                long sum2= (sum[i]-sum[m1])-nums[m1-1]*(long)(i+1-m1)\n                +((long)nums[m1-1]*(long)(m1+1-m)-(sum[m1-1]-sum[m-1]));\n                if(sum2<=k){ans=Math.Max(ans, i-m+1);r=m-1;}\n                else l=m+1;\n\n            }\n              int m2=(i+l)/2;\n                long sum3= (sum[i]-sum[m2])-nums[m2-1]*(long)(i+1-m2)\n                +(nums[m2-1]*(m2-l)-sum[m2-1]+sum[l-1]);\n                if (sum3<=k&& !check) ans=Math.Max(ans, i-l+1); \n \n        }\n        return ans;\n    }\n}\n```
['C#']