#include <bits/stdc++.h>
using namespace std;
const int MAX = 100 * 1000;
deque<pair<int, int> > d[2][2];
int n, D, second;
pair<int, int> best;
long long a[MAX + 10];
int head;
void fill_a() {
  int i = 0;
  for (deque<pair<int, int> >::iterator it = d[1][0].begin();
       it != d[1][0].end(); it++, i++) {
    a[i] = it->first;
    if (i != 0) a[i] += a[i - 1];
  }
  head = i;
}
void best_upd(pair<int, int> a) {
  if (a.first > best.first)
    best = a;
  else if (a.first == best.first && a.second < best.second)
    best = a;
}
void add_10(int f, int cnt) {
  int ret = upper_bound(a, a + head, second - f) - a - 1;
  if (ret >= 0) {
    ret = min(ret, (int)d[1][0].size() - 1);
    best_upd(pair<int, int>(ret + 1 + cnt, f + a[ret]));
  } else
    best_upd(pair<int, int>(cnt, f));
}
void way2() {
  fill_a();
  add_10(0, 0);
  if (d[1][1].empty() || d[1][1].front().first > second) return;
  int f = d[1][1].front().first;
  int carry = 1;
  int cnt = 0;
  for (deque<pair<int, int> >::iterator it = d[1][1].begin();
       it != d[1][1].end(); it++)
    carry += it->second - 1;
  cnt += d[1][1].size();
  d[1][1].pop_front();
  for (deque<pair<int, int> >::iterator it = d[0][1].begin();
       it != d[0][1].end(); it++)
    carry += it->second - 1;
  cnt += d[0][1].size();
  while (1) {
    while (carry && !d[0][0].empty()) {
      carry--;
      cnt++;
      d[0][0].pop_back();
    }
    while (carry && !d[1][0].empty()) {
      carry--;
      cnt++;
      d[1][0].pop_back();
    }
    add_10(f, cnt);
    if (d[1][1].empty()) break;
    f += d[1][1].front().first;
    if (f > second) break;
    d[1][1].pop_front();
    carry++;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> D >> second;
  for (int i = 0; i < n; i++) {
    int c, f, l;
    cin >> c >> f >> l;
    bool a, b;
    b = (c > 0 ? 1 : 0);
    a = (l >= D ? 1 : 0);
    d[a][b].push_back(pair<int, int>(f, c));
  }
  for (int i = 0; i < 2; i++) sort(d[1][i].begin(), d[1][i].end());
  way2();
  cout << best.first << " " << best.second << endl;
  return 0;
}
