Language: C++

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;
LL N,M,V,P;

int check(vector<int>& a, int vidx){
    int v=a[vidx];
    int of1=P-1;
    int of2=upper_bound(a.begin(),a.end(),v)-a.begin();
    int ar=N-P+1,al=of2,tgt=v+M;
    int alpha=V-of1-of2;
    cerr<<"\n v:"<<v<<" "<<of1<<" "<<of2<<" alpha:"<<alpha<<endl;
    if(alpha<=0){
        if(a[N-P]<=tgt){
            return 1;
        }else{
            return 0;
        }
    }
    int nn=ar-al,f=0;
    vector<int> b(nn);
    int under=-1;
    LL sm=0;
    cerr<<"al:"<<al<<" ar:"<<ar<<" nn:"<<nn<<" "<<endl;
    FOR(i,0,nn){
        b[i]=a[al+i];
        sm+=min(M,tgt-b[i]);
    }
    if(sm<1LL*alpha*M){
        return 0;
    }

    return 1;
}

int main(){
    LL n,m,v,p;
    cin>>n>>m>>v>>p;
    N=n;M=m;V=v;P=p;
    vector<int> a(n);
    FOR(i,0,n){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    FOR(i,0,n){
        //cerr<<a[i]<<" ";
    }
    if(check(a,0)){
        //cerr<<"all"<<endl;
        cout<<n<<endl;
        return 0;
    }
    int l=0,r=n-p;//l:ng r:ok
    int mm=(l+r+1)/2;
    while(r!=mm){
        if(check(a,mm)){
            r=mm;
        }else{
            l=mm;
        }
        mm=(l+r+1)/2;
        //cerr<<"mm:"<<mm<<endl;
    }

    cout<<n-mm<<endl;

}


Compiler output:
a.cc: In function 'int check(std::vector<int>&, int)':
a.cc:66:16: error: no matching function for call to 'min(long long int&, int)'
   66 |         sm+=min(M,tgt-b[i]);
      |             ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:66:16: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   66 |         sm+=min(M,tgt-b[i]);
      |             ~~~^~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:10:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:66:16: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   66 |         sm+=min(M,tgt-b[i]);
      |             ~~~^~~~~~~~~~~~