Language: C++

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

struct Chara{
	string name;
	ll vote;
	bool operator<(const Chara &c)const{
		if(vote==c.vote) return name<c.name;
		return vote>c.vote;
	}
};

ll n,m,k,l;
Chara charas[100010];
vector<Chara> favs,unfavs;

bool Check(int x){
	if(x>k||x>m) return false;
	if(unfavs.size()<k-x+1) return false;
	ll cost=0;

	REP(i,0,x){
		cost+=max(0,unfavs[k-x].vote-favs[i].vote+(favs[i].name>unfavs[k-x].name));
		if(cost>l) return false;
	}
	
	return true;
}

void Solve(){
	while(true){
		cin >> n >> m >> k >> l;
		if(n+m+k+l==0) break;
		REP(i,0,n) cin >> charas[i].name >> charas[i].vote;
		unordered_set<string> fav_names(m);
		REP(i,0,m){
			string name;
			cin >> name;
			fav_names.insert(name);
		}
		sort(charas,charas+n);
		REP(i,0,n){
			if(fav_names.find(charas[i].name)!=fav_names.end()) favs.push_back(charas[i]);
			else unfavs.push_back(charas[i]);
		}

		int lb=0,ub=m+10;
		while(true){
			if(ub-lb<=1){
				if(Check(ub)) lb=ub;
				break;
			}
			int mid=(lb+ub)/2;
			if(Check(mid)) lb=mid;
			else ub=mid;
		}

		cout << lb << endl;

		favs.clear();
		unfavs.clear();
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Compiler output:
a.cc: In function 'bool Check(int)':
a.cc:70:26: error: no matching function for call to 'max(int, ll)'
   70 |                 cost+=max(0,unfavs[k-x].vote-favs[i].vote+(favs[i].name>unfavs[k-x].name));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:1:
/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:70:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   70 |                 cost+=max(0,unfavs[k-x].vote-favs[i].vote+(favs[i].name>unfavs[k-x].name));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:2:
/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:70:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   70 |                 cost+=max(0,unfavs[k-x].vote-favs[i].vote+(favs[i].name>unfavs[k-x].name));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~