#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int n, deg;
int Get(int s) {
  int cnt1 = 0;
  int sum = 0;
  for (int i = 0; i < v.size(); i++) {
    sum += v[i].first;
    if (sum > s) break;
    cnt1++;
  }
  int key = -1;
  for (int i = 0; i < v.size(); i++) {
    if (v[i].first <= s && v[i].second >= 1) {
      key = i;
      break;
    }
  }
  if (key == -1) return cnt1;
  sum = v[key].first;
  int cnt2 = 0;
  for (int i = 0; i < v.size(); i++) {
    if (i == key) continue;
    sum += v[i].first;
    if (sum > s) break;
    cnt2++;
  }
  return max(cnt1, min(n, cnt2 + 1 + deg));
}
int main() {
  int i, j, h;
  int T, m;
  int d, s, c, f, l;
  scanf("%d%d%d", &n, &d, &s);
  deg = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d%d%d", &c, &f, &l);
    deg += c;
    deg = min(deg, n);
    if (l >= d) {
      v.push_back(make_pair(f, c));
    }
  }
  sort(v.begin(), v.end());
  int max_cnt = Get(s);
  int head = 0;
  int tail = s;
  int ans = -1;
  while (head <= tail) {
    int mid = (head + tail) >> 1;
    if (Get(mid) == max_cnt) {
      tail = mid - 1;
      ans = mid;
    } else {
      head = mid + 1;
    }
  }
  printf("%d %d\n", max_cnt, ans);
}
