#include <bits/stdc++.h>
using namespace std;
const int maxn = 201010;
struct award {
  int c, w;
  bool operator<(award b) const {
    if (c == b.c) return w > b.w;
    return c < b.c;
  }
} a[maxn], b[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  int n, m, d;
  cin >> n >> m >> d;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].c >> a[i].w;
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i].c >> b[i].w;
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + m + 1);
  if (a[n].w + b[m].w > d) {
    cout << 0;
    return 0;
  }
  long long curW = a[n].w, curC = a[n].c;
  int it = m + 1;
  while (it > 1 && b[it - 1].w + curW <= d) {
    it--;
    curW += b[it].w;
    curC += b[it].c;
  }
  long long ans = curC;
  for (int i = n - 1; i >= 1; i--) {
    curC += a[i].c;
    curW += a[i].w;
    while (it <= m && curW > d) {
      curW -= b[it].w;
      curC -= b[it].c;
      it++;
    }
    if (it > m) {
      break;
    }
    ans = max(ans, curC);
  }
  cout << ans;
  return 0;
}
