#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double EPS = 1e-6;
int main() {
  int n, d, S;
  scanf("%d %d %d", &n, &d, &S);
  vector<pair<int, int> > cand;
  int free = 0;
  for (int i = 0; i < n; i++) {
    int c, f, l;
    scanf("%d %d %d", &c, &f, &l);
    if (l >= d) cand.push_back(make_pair(f, c));
    free = min(free + c, n);
  }
  sort(cand.begin(), cand.end());
  int m = ((int)(cand).size());
  pair<int, int> res = make_pair(0, 0);
  for (int i = 0; i < m; i++)
    if (res.second + cand[i].first <= S) {
      res.first++;
      res.second += cand[i].first;
    } else
      break;
  int first = -1;
  for (int i = 0; i < m; i++)
    if (cand[i].second > 0) {
      first = i;
      break;
    }
  if (first != -1) {
    pair<int, int> now = make_pair(min(1 + free, n), cand[first].first);
    if (cand[first].first <= S &&
        (now.first > res.first ||
         (now.first == res.first && now.second < res.second)))
      res = now;
    for (int i = 0; i < m && now.first < n; i++) {
      if (i == first) continue;
      if (now.second + cand[i].first <= S) {
        now.first++;
        now.second += cand[i].first;
      } else
        break;
      if (now.first > res.first ||
          (now.first == res.first && now.second < res.second))
        res = now;
    }
  }
  printf("%d %d\n", res.first, res.second);
  return 0;
}
