#include <bits/stdc++.h>
using namespace std;
typedef struct Robo {
  long long int c, f, x;
} Robo;
long long int n, d, s;
Robo carry[100500];
Robo dcarry[100500];
bool comp(Robo a, Robo b) {
  if (a.x < d && b.x < d) return a.x < b.x;
  if (a.x < d) return false;
  if (b.x < d) return true;
  return a.f < b.f;
}
int main() {
  cin >> n >> d >> s;
  long long int a, b, c;
  long long int menor, ind;
  long long int carrega = 0;
  menor = 0x3f3f3f3f;
  long long int tamc = 0;
  long long int tamd = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    Robo r;
    r.c = a;
    r.f = b;
    r.x = c;
    if (a == 0) {
      dcarry[tamd++] = (r);
    } else {
      carry[tamc++] = (r);
      carrega += r.c;
    }
  }
  long long int res = 0, res_fuel;
  sort(dcarry, dcarry + tamd, comp);
  long long int fuel = 0;
  long long int x = 0;
  for (int i = 0; i < tamd; i++) {
    if (dcarry[i].x >= d && fuel + dcarry[i].f <= s) {
      x++;
      fuel += dcarry[i].f;
    } else
      break;
  }
  res = x;
  res_fuel = fuel;
  x = 0;
  carrega = min(carrega + 1, tamc + tamd);
  sort(carry, carry + tamc, comp);
  fuel = 0;
  if (tamc > 0 && carry[0].x >= d && carry[0].f <= s) {
    x = carrega;
    fuel = carry[0].f;
    int i = 1;
    int j = 0;
    while (1) {
      if (i == tamc && j == tamd) break;
      if (x == tamc + tamd) break;
      if (i == tamc) {
        if (dcarry[j].x >= d && fuel + dcarry[j].f <= s) {
          x++;
          fuel += dcarry[j].f;
          j++;
          continue;
        } else {
          break;
        }
      }
      if (j == tamd) {
        if (carry[i].x >= d && fuel + carry[i].f <= s) {
          x++;
          fuel += carry[i].f;
          i++;
          continue;
        } else {
          break;
        }
      }
      if (comp(carry[i], dcarry[j])) {
        if (carry[i].x >= d && fuel + carry[i].f <= s) {
          x++;
          fuel += carry[i].f;
          i++;
          continue;
        } else {
          break;
        }
      } else {
        if (dcarry[j].x >= d && fuel + dcarry[j].f <= s) {
          x++;
          fuel += dcarry[j].f;
          j++;
          continue;
        } else {
          break;
        }
      }
    }
    if (x > res) {
      res = x;
      res_fuel = fuel;
    } else if (x == res) {
      res_fuel = min(res_fuel, fuel);
    }
  }
  cout << res << ' ' << res_fuel << '\n';
  return 0;
}
