#include <bits/stdc++.h>
using namespace std;
int n;
long long s, d;
long long c, f, l;
vector<long long> dcarry, dncarry, dcarrycost, dncarrycost;
long long carrycap, carriers, ncarriers;
void prefix(vector<long long>& ref, vector<long long>& pre) {
  for (int i = 0; i < ref.size(); i++) {
    if (i == 0)
      pre.push_back(ref[i]);
    else
      pre.push_back(pre.back() + ref[i]);
  }
}
long long fun(long long lim) {
  long long val = upper_bound(dncarrycost.begin(), dncarrycost.end(), lim) -
                  dncarrycost.begin();
  if (dcarrycost.empty() || dcarrycost[0] > lim) return val;
  int temp = upper_bound(dcarrycost.begin(), dcarrycost.end(), lim) -
             dcarrycost.begin();
  long long extra = carrycap - (carriers - temp);
  val = max(val, carriers + min(extra, ncarriers));
  for (int i = 0; i < dncarry.size(); i++) {
    long long used = dncarrycost[i];
    long long rem = lim - used;
    if (dcarrycost.empty() || dcarrycost[0] > rem) {
      val = max(val, i + 1LL);
      break;
    }
    int temp = upper_bound(dcarrycost.begin(), dcarrycost.end(), rem) -
               dcarrycost.begin();
    long long extra = carrycap - (carriers - temp);
    val = max(val, carriers + i + 1 + min(extra, ncarriers - i - 1));
  }
  return val;
}
long long bsrch(long long l, long long r) {
  if (l == r) return l;
  long long mid = (l + r) / 2;
  if (fun(r) == fun(mid))
    return bsrch(l, mid);
  else
    return bsrch(mid + 1, r);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> d >> s;
  for (int i = 0; i < n; i++) {
    cin >> c >> f >> l;
    if (l >= d) {
      if (c != 0)
        dcarry.push_back(f);
      else
        dncarry.push_back(f);
    }
    carrycap += c;
    if (c == 0)
      ncarriers++;
    else
      carriers++;
  }
  sort(dcarry.begin(), dcarry.end());
  sort(dncarry.begin(), dncarry.end());
  prefix(dcarry, dcarrycost);
  prefix(dncarry, dncarrycost);
  f = bsrch(0, s);
  cout << fun(f) << ' ' << f;
  return 0;
}
