#include <bits/stdc++.h>
using namespace std;
struct node {
  long long c, f, l;
};
bool operator<(node a, node b) { return a.f < b.f; }
long long n, dx, fx, bn, tot, i, tf, fn, first, xn, sum, xx;
node a[100004], b[100004];
bool can;
int main() {
  cin >> n >> dx >> fx;
  bn = -1;
  tot = 0;
  for (i = 0; i < n; i++) {
    cin >> a[i].c >> a[i].f >> a[i].l;
    tot += a[i].c;
    if (a[i].l >= dx) {
      bn++;
      b[bn] = a[i];
    }
  }
  bn++;
  sort(b, b + bn);
  can = false;
  tf = 0;
  fn = 0;
  first = -1;
  for (i = 0; i < bn; i++) {
    if (tf + b[i].f <= fx) {
      tf += b[i].f;
      if (b[i].c != 0 && first == -1) {
        first = i;
        can = true;
      }
      fn++;
    }
  }
  if (can == false) {
    first = -1;
    for (i = 0; i < bn; i++) {
      if (b[i].c != 0) {
        first = i;
        break;
      }
    }
    if (first != -1) {
      if (b[first].f <= fx) {
        tf = b[first].f;
        xx = 0;
        for (i = 0; i < bn; i++) {
          if (tf + b[i].f > fx) break;
          tf += b[i].f;
          xx++;
        }
        if (tot + xx + 1 > fn) {
          can = true;
          fn = xx + 1;
        }
      }
    }
  }
  if (can == true) {
    if (tot + fn > n) {
      cout << n << " ";
      xn = n - tot;
      if (xn - 1 < first) {
        sum = 0;
        for (i = 0; i <= xn - 2; i++) sum += b[i].f;
        sum += b[first].f;
      } else {
        sum = 0;
        for (i = 0; i < xn; i++) sum += b[i].f;
      }
      cout << sum << endl;
    } else {
      cout << tot + fn << " ";
      if (fn - 1 < first) {
        sum = 0;
        for (i = 0; i < fn - 1; i++) sum += b[i].f;
        sum += b[first].f;
      } else {
        sum = 0;
        for (i = 0; i < fn; i++) sum += b[i].f;
      }
      cout << sum << endl;
    }
  } else {
    cout << fn << " ";
    sum = 0;
    for (i = 0; i < fn; i++) sum += b[i].f;
    cout << sum << endl;
  }
  return 0;
}
