Language: C++

struct S{
  char s[11];
  int x;
  bool operator<(const S &r)const{
    if(x!=r.x)return x>r.x;
    return strcmp(s,r.s)<0;
  }
};
S chara[100000];
int n,m,k,l;

vector<S> like, dislike;
ll calc(int m){
  ll need=0;
  if(dislike.size()<k-m+1)return 0;
  rep(i,m){
    //cerr<<"hoge: "<<dislike[k-m].x-like[i].x<<endl;
    need+=max(0,dislike[k-m].x-like[i].x+
    (strcmp(dislike[k-m].s,like[i].s)<0));
  }
  //cerr<<"m: "<<m<<" need: "<<need<<endl;
  return need;
}

int main(){
  while(scanf("%d%d%d%d",&n,&m,&k,&l),n){
    set<string> names;
    rep(i,n)scanf("%s%d",chara[i].s,&chara[i].x);
    rep(i,m){
      char in[11]; scanf("%s",in);
      names.insert(string(in));
    }
    like.clear(); dislike.clear();
    rep(i,n){
      if(names.count(chara[i].s))like.pb(chara[i]);
      else dislike.pb(chara[i]);
    }
    sort(all(like)); sort(all(dislike));
    //rep(i,dislike.size())cerr<<dislike[i].s<<" "<<dislike[i].x<<endl;
    
    int lo=0, hi=min(m,k)+1, mid;
    while(lo+1<hi){
      mid=(lo+hi)/2;
      if(calc(mid)<=l)lo=mid; else hi=mid;
    }
    printf("%d\n",lo);
  }
  return 0;
}

Compiler output:
a.cc: In member function 'bool S::operator<(const S&) const':
a.cc:6:12: error: 'strcmp' was not declared in this scope
    6 |     return strcmp(s,r.s)<0;
      |            ^~~~~~
a.cc:1:1: note: 'strcmp' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
  +++ |+#include <cstring>
    1 | struct S{
a.cc: At global scope:
a.cc:12:1: error: 'vector' does not name a type
   12 | vector<S> like, dislike;
      | ^~~~~~
a.cc:13:1: error: 'll' does not name a type
   13 | ll calc(int m){
      | ^~
a.cc: In function 'int main()':
a.cc:26:9: error: 'scanf' was not declared in this scope
   26 |   while(scanf("%d%d%d%d",&n,&m,&k,&l),n){
      |         ^~~~~
a.cc:27:5: error: 'set' was not declared in this scope
   27 |     set<string> names;
      |     ^~~
a.cc:27:9: error: 'string' was not declared in this scope
   27 |     set<string> names;
      |         ^~~~~~
a.cc:27:17: error: 'names' was not declared in this scope
   27 |     set<string> names;
      |                 ^~~~~
a.cc:28:9: error: 'i' was not declared in this scope
   28 |     rep(i,n)scanf("%s%d",chara[i].s,&chara[i].x);
      |         ^
a.cc:28:5: error: 'rep' was not declared in this scope
   28 |     rep(i,n)scanf("%s%d",chara[i].s,&chara[i].x);
      |     ^~~
a.cc:33:5: error: 'like' was not declared in this scope
   33 |     like.clear(); dislike.clear();
      |     ^~~~
a.cc:33:19: error: 'dislike' was not declared in this scope
   33 |     like.clear(); dislike.clear();
      |                   ^~~~~~~
a.cc:38:10: error: 'all' was not declared in this scope
   38 |     sort(all(like)); sort(all(dislike));
      |          ^~~
a.cc:38:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   38 |     sort(all(like)); sort(all(dislike));
      |     ^~~~
      |     short
a.cc:41:18: error: 'min' was not declared in this scope; did you mean 'main'?
   41 |     int lo=0, hi=min(m,k)+1, mid;
      |                  ^~~
      |                  main
a.cc:43:7: error: 'mid' was not declared in this scope
   43 |       mid=(lo+hi)/2;
      |       ^~~
a.cc:44:10: error: 'calc' was not declared in this scope
   44 |       if(calc(mid)<=l)lo=mid; else hi=mid;
      |          ^~~~
a.cc:46:5: error: 'printf' was not declared in this scope
   46 |     printf("%d\n",lo);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | struct S{