Language: C++

#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	llong N, M, V, P;
	vector<llong> A;

	cin >> N >> M >> V >> P;
	A.resize(N);
	for (auto &in: A) {
		cin >> in;
	}
	sort(ALL(A));

	for (auto a: A) {
		cerr << a << " ";
	}
	cerr << endl;

	int ok = N, ng = -1;
	while (abs(ok - ng) > 1) {

		int mid = (ok + ng) / 2;
		cerr << ok << " " << ng << " " << mid << endl;

		if (A[mid] + M < A[N - P]) {
			ng = mid;
		}
		else if (mid >= V - 1) {
			ok = mid;
		}
		else {
			if (V - 1 <= P - 1) {
				ok = mid;
			}
			else {
				multiset<llong, greater<>> ms;
				for (int i = 0; i < V - (P - 1); ++i) {
					ms.insert(M);
				}
				for (int i = 0; i <= N - P && ms.size(); ++i) {
					llong now = *ms.begin();
					ms.erase(ms.begin());
					now -= A[mid] + M - A[i];
					if (now > 0) {
						ms.insert(now);
					}
				}

				if (ms.size() == 0) {
					ok = mid;
				}
				else {
					ng = mid;
				}
			}
		}

	}

	int ans = 0;
	for (int i = ok; i <= min(N-1, ok + 100); ++i) {
		if (A[i] + M < A[N - P]) continue;
		multiset<llong, greater<>> ms;
		for (int i = 0; i < V - (P - 1); ++i) {
			ms.insert(M);
		}
		for (int j = 0; j <= N - P && ms.size(); ++j) {
			llong now = *ms.begin();
			ms.erase(ms.begin());
			now -= A[i] + M - A[j];
			if (now > 0) {
				ms.insert(now);
			}

			if (ms.size() == 0) {
				ans = i;
			}
			else {
				break;
			}
		}
	}

	cout << N - i << endl;

	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:73:34: error: no matching function for call to 'min(llong, int)'
   73 |         for (int i = ok; i <= min(N-1, ok + 100); ++i) {
      |                               ~~~^~~~~~~~~~~~~~~
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:1:
/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:73:34: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   73 |         for (int i = ok; i <= min(N-1, ok + 100); ++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:
/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:73:34: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   73 |         for (int i = ok; i <= min(N-1, ok + 100); ++i) {
      |                               ~~~^~~~~~~~~~~~~~~
a.cc:96:21: error: 'i' was not declared in this scope
   96 |         cout << N - i << endl;
      |                     ^