#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
int deg = 0, total = 0;
vector<pair<int, int> > data;
int n, d, s;
pair<int, int> go(int s) {
  int x, y;
  int ret = 0;
  int now = 0;
  for (typeof(data.begin()) it = data.begin(); it != data.end(); it++) {
    if (it->first + now <= s) {
      now += it->first;
      ++ret;
    } else
      break;
  }
  x = ret;
  y = -now;
  int buy = 0;
  while (buy < data.size() && data[buy].second == 0) ++buy;
  if (buy == data.size() || data[buy].first > s) return make_pair(x, y);
  pair<int, int> ans = make_pair(x, y);
  now = data[buy].first;
  ans = max(ans, make_pair(min(n, deg + 1), -now));
  int afford = 0;
  for (int i = 0; i < data.size(); i++)
    if (i != buy) {
      if (now + data[i].first <= s)
        ++afford;
      else
        break;
      now += data[i].first;
      ans = max(ans, make_pair(min(n, deg + 1 + afford), -now));
    }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> d >> s;
  for (int i = 0; i < n; i++) {
    int c, f, l;
    cin >> c >> f >> l;
    deg += c;
    deg = min(deg, n);
    if (l < d) {
      ++total;
    } else
      data.push_back(make_pair(f, c));
  }
  sort(data.begin(), data.end());
  pair<int, int> out = go(s);
  cout << out.first << " " << -out.second << endl;
  return 0;
}
