Only Binary Search || No sliding window || C++ / Java  / Python 🔥
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   \n    int bs(int i,vector<int>& a,vector<long long>&p,long long k)\n    {\n        int l=0,h=i;\n        int ans=i;\n        if(i==a.size()-2)\n         {\n             for(auto &x:a)\n              cout<<x<<" ";\n            cout<<endl;\n         cout<<"s1  l1.  s2.  l2.  cost   k.   low   high "<<endl;\n         }\n        while(l<h)\n        {\n            int m=l+(h-l)/2;\n            int w=(m+i)/2; // median index\n            long long s1 = p[i]-p[w]; //sum of elements > median\n            long long l1=i-w;\n            int left=m-1;\n            if(m-1<0)\n             left=m;\n            long long s2 ;\n            if(m!=0)\n             s2= p[w]-p[left]; //sum of elements < median\n            else\n             s2=p[w];\n            long long l2=w-left;\n            if(m==0)\n             l2++;\n            \n            long long cost=0;\n            cost+=s1-l1*a[w];\n            cost+=l2*a[w]-s2;\n            if(cost<=k)\n            {\n                ans=min(ans,m);\n                h=m;\n            }\n            else\n             l=m+1;\n           if(i==a.size()-2)\n        {\n            cout<<s1<<"   "<<l1<<"    "<<s2<<"     "<<l2<<"    "<<cost<<"    "<<k<<"    "<<l<<"    "<<h<<endl;\n        }  \n\n        }\n        \n        return ans;\n    }\n    int maxFrequencyScore(vector<int>& a, long long k) {\n        \n           int n=a.size();\n           sort(a.begin(),a.end());\n           vector<long long >p(n,0);\n           p[0]=a[0];\n           for(int i=1;i<n;i++)\n            p[i]=a[i]+p[i-1];\n          int ans=1;\n          for(int i=n-1;i>0;i--)\n          {\n              int j=bs(i,a,p,k);\n              if(i==n-2)\n              cout<<"j is :: "<<j<<endl;\n              ans=max(ans,i-j+1);\n          }\n          return ans;\n    }\n};\n```
['Binary Search', 'Sorting', 'C++', 'Python3']