#include <bits/stdc++.h>
using namespace std;
struct robot {
  long long carry, fuel, l;
};
bool cmp(const robot &x, const robot &y) {
  if (x.fuel == y.fuel) {
    return x.carry > y.carry;
  }
  return x.fuel < y.fuel;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, d, s;
  cin >> n >> d >> s;
  bool found = false;
  vector<robot> arr;
  for (long long i = 0; i < n; ++i) {
    long long c, f, l;
    cin >> c >> f >> l;
    if (l >= d && f <= s) {
      found = true;
    }
    arr.push_back({c, f, l});
  }
  if (!found) {
    cout << "0 0\n";
    return 0;
  }
  sort(arr.begin(), arr.end(), cmp);
  pair<long long, long long> noTree = {0, 0};
  for (long long i = 0; i < n; ++i) {
    if (noTree.second + arr[i].fuel <= s && arr[i].l >= d) {
      noTree.first++;
      noTree.second += arr[i].fuel;
    }
  }
  long long pos = -1;
  for (long long i = 0; i < n; ++i) {
    if (arr[i].fuel <= s && arr[i].l >= d && arr[i].carry > 0) {
      pos = i;
      break;
    }
  }
  pair<long long, long long> tree = {0, 0};
  if (pos >= 0) {
    tree.first = 1 + arr[pos].carry;
    tree.second = arr[pos].fuel;
    for (long long i = 0; i < n; ++i) {
      if (i == pos) continue;
      if (arr[i].carry > 0) {
        tree.first += arr[i].carry;
      }
    }
    bool leaveLoop = false;
    if (tree.first >= n) {
      tree.first = n;
      leaveLoop = true;
    }
    if (!leaveLoop) {
      for (long long i = 0; i < n; ++i) {
        if (i == pos) continue;
        if (tree.second + arr[i].fuel <= s && arr[i].l >= d) {
          tree.first++;
          tree.second += arr[i].fuel;
          if (tree.first == n) break;
        }
      }
    }
  }
  if (tree.first < noTree.first)
    tree = noTree;
  else if (tree.first == noTree.first && tree.second > noTree.second)
    tree = noTree;
  cout << tree.first << ' ' << tree.second << '\n';
}
