#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vc = vector<T>;
using pii = pair<long long, long long>;
void xmax(long long& a, long long b) { a = max(a, b); }
void xmin(long long& a, long long b) { a = min(a, b); }
void print(vc<long long>& a, string second) {
  cerr << "prinitng " << second << ": ";
  for (long long i = 0; i < a.size(); i++) {
    cerr << a[i] << " ";
  }
  cerr << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, d, second;
  cin >> n >> d >> second;
  long long mini = second + 5;
  long long anz_plus = 0;
  long long own_start = 0;
  multiset<long long> term;
  for (long long i = 0; i < n; i++) {
    long long c, first, l;
    cin >> c >> first >> l;
    if (l < d) {
      anz_plus += c;
    } else {
      term.insert(first);
      if (c >= 1) {
        xmin(mini, first);
        anz_plus += c;
      }
    }
  }
  long long cur = second;
  long long anz = 0;
  for (auto tap : term) {
    if (cur >= tap) {
      cur -= tap;
      anz++;
    }
  }
  long long need = second - cur;
  long long anz2 = 0;
  long long cur2 = second;
  long long need2 = 0;
  if (cur2 >= mini) {
    cur2 -= mini;
    anz2 = anz_plus + 1;
    if (own_start != 0) anz2 += own_start - 1;
    long long rem = 0;
    for (auto tap : term) {
      if (tap == mini && rem == 0) {
        rem = 1;
        continue;
      }
      if (cur2 >= tap && anz2 < n) {
        cur2 -= tap;
        anz2++;
      }
    }
    need2 = second - cur2;
  }
  anz2 = min(anz2, n);
  long long res, fuel;
  if (anz == anz2) {
    res = anz;
    fuel = min(need, need2);
  } else {
    if (anz > anz2) {
      res = anz;
      fuel = need;
    } else {
      res = anz2;
      fuel = need2;
    }
  }
  cout << res << " " << fuel << "\n";
}
