#include <bits/stdc++.h>
using namespace std;
int N, D, S;
int sol = 0;
long long part[100010];
long long cost = 1000000000100000000LL;
struct Robots {
  int c, f, l;
} R[100010];
vector<pair<int, int> > cable;
vector<int> able, unable, cunable;
int cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  }
  return a.second > b.second;
}
pair<int, int> check(int ls, int ld, long long s_aux) {
  if (ls > ld) return make_pair(0, 0);
  pair<int, int> ret = make_pair(0, 0);
  while (ls <= ld) {
    int mid = (ls + ld) / 2;
    if (part[mid] <= s_aux) {
      ret.first = mid + 1;
      ret.second = part[mid];
      ls = mid + 1;
    } else {
      ld = mid - 1;
    }
  }
  return ret;
}
int main() {
  int i, j, p, q = 0;
  long long caratori = 0;
  cin >> N >> D >> S;
  for (i = 1; i <= N; i++) {
    cin >> R[i].c >> R[i].f >> R[i].l;
    if (R[i].c >= 1) {
      q++;
      if (R[i].l >= D) {
        cable.push_back(make_pair(R[i].f, R[i].c));
      }
      caratori += (R[i].c - 1);
    } else {
      if (R[i].l >= D) {
        able.push_back(R[i].f);
      } else {
        unable.push_back(R[i].f);
      }
    }
  }
  sort(able.begin(), able.end());
  sort(unable.begin(), unable.end());
  sort(cable.begin(), cable.end(), cmp);
  for (i = 0; i < able.size(); i++) {
    if (i == 0) {
      part[i] = able[i];
      continue;
    }
    part[i] = part[i - 1] + able[i];
  }
  long long sum_aux = 0;
  for (i = 0; i < able.size(); i++) {
    if (sum_aux + able[i] <= S) {
      sum_aux += able[i];
      sol++;
      cost = sum_aux;
    } else
      break;
  }
  long long sum = 0;
  long long from_unable = 0;
  long long from_able_last = 0;
  for (i = 0; i < cable.size(); i++) {
    if (sum + cable[i].first <= S) {
      sum += cable[i].first;
      caratori++;
      long long sol_part = q;
      long long cost_part = sum;
      while (from_unable < caratori && from_unable < unable.size()) {
        from_unable++;
      }
      while (from_able_last < able.size() &&
             from_able_last + from_unable < caratori) {
        from_able_last++;
      }
      pair<int, int> aux =
          check(0, (int)able.size() - from_able_last - 1, S - sum);
      sol_part += aux.first;
      cost_part += aux.second;
      sol_part += from_able_last;
      sol_part += from_unable;
      if (sol_part > sol || (sol_part == sol && cost_part < cost)) {
        sol = sol_part;
        cost = cost_part;
      }
    } else
      break;
  }
  if (cost == 1000000000100000000LL) cost = 0;
  cout << sol << " " << cost << '\n';
  return 0;
}
