#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, d, s;
  cin >> n >> d >> s;
  vector<int> fuelcerollega;
  vector<int> fuelnocerollega;
  int numceronollega = 0;
  int minimofuelnocero = 2000000000;
  int numnocero = 0;
  long long int aridadnocero = 1;
  for (int i = 0; i < n; i++) {
    int c, f, l;
    cin >> c >> f >> l;
    if (c == 0) {
      if (l >= d)
        fuelcerollega.push_back(f);
      else
        numceronollega++;
    } else {
      if (l >= d) {
        fuelnocerollega.push_back(f);
        minimofuelnocero = min(minimofuelnocero, f);
      }
      numnocero++;
      aridadnocero += c - 1;
    }
  }
  pair<int, int> sol;
  sort(fuelcerollega.begin(), fuelcerollega.end());
  sort(fuelnocerollega.begin(), fuelnocerollega.end());
  {
    int amountfuel = 0;
    int amountnumber = 0;
    for (int i = 0;
         i < int(fuelcerollega.size()) and amountfuel + fuelcerollega[i] <= s;
         i++) {
      amountfuel += fuelcerollega[i];
      amountnumber++;
    }
    sol = pair<int, int>(amountnumber, -amountfuel);
  }
  if (minimofuelnocero <= s) {
    int amountfuel = minimofuelnocero;
    int amountnumber = numnocero;
    if (numceronollega <= aridadnocero) {
      aridadnocero -= numceronollega;
      amountnumber += numceronollega;
      numceronollega = 0;
    } else {
      numceronollega -= aridadnocero;
      amountnumber += aridadnocero;
      aridadnocero = 0;
    }
    int ifuelcerollega = 0;
    if (aridadnocero >= int(fuelcerollega.size()))
      amountnumber += int(fuelcerollega.size());
    else {
      amountnumber += aridadnocero;
      for (; ifuelcerollega < int(fuelcerollega.size()) - aridadnocero and
             amountfuel + fuelcerollega[ifuelcerollega] <= s;
           ifuelcerollega++) {
        amountfuel += fuelcerollega[ifuelcerollega];
        amountnumber++;
      }
    }
    {
      pair<int, int> nextsol(amountnumber, -amountfuel);
      sol = max(sol, nextsol);
    }
    for (int i = 1; i < int(fuelnocerollega.size()); i++) {
      amountfuel += fuelnocerollega[i];
      if (numceronollega > 0) {
        amountnumber++;
        numceronollega--;
      } else if (int(fuelcerollega.size()) - aridadnocero > 0) {
        aridadnocero++;
        if (ifuelcerollega <= int(fuelcerollega.size()) - aridadnocero) {
          amountnumber++;
        } else {
          ifuelcerollega--;
          amountfuel -= fuelcerollega[ifuelcerollega];
        }
      }
      while (amountfuel > s and ifuelcerollega > 0) {
        ifuelcerollega--;
        amountfuel -= fuelcerollega[ifuelcerollega];
        amountnumber--;
      }
      if (amountfuel > s) break;
      pair<int, int> nextsol(amountnumber, -amountfuel);
      sol = max(sol, nextsol);
    }
  }
  cout << sol.first << " " << -sol.second << endl;
}
