Language: C++

/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppi                      pair <int , pii>               
#define    sp(x)                    setprecision(x)
  
int32_t main()
{
    speed upp
    int n,m,v,p,ans,sum=0;
    cin>>n>>m>>v>>p;
    int a[n+1];
    f(i,1,n)
        cin>>a[i];
    sort(a+1,a+n+1);
    v=v-p;
    v=max(0,v);
    int l=1,r=n-p;
    ans=r+1;
    while(l<=r)
    {
        int mid=(l+r)>>1;
        if(a[mid]+m<a[n-p+1])
            l=mid+1;
        else
        {
            sum=0;
            f(i,1,n-p+1)
            {
                if(i==mid)
                    continue;
                int x=a[mid]+m-a[i];
                x=min(m,x);
                sum+= x;
                
            }
            
            if ( v*m  <= sum )
            {
                r=mid-1;
                ans=mid;
            }
            else    
                l=mid+1;
        }
    }
    
    cout<<n-ans+1;
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:35:10: error: no matching function for call to 'max(int, long long int&)'
   35 |     v=max(0,v);
      |       ~~~^~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:35:10: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   35 |     v=max(0,v);
      |       ~~~^~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:35:10: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   35 |     v=max(0,v);
      |       ~~~^~~~~