#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160")
using namespace std;
pair<bool, pair<int, int> > a[100100];
int main() {
  int n, d, S;
  int c, f, l;
  scanf("%d%d%d", &n, &d, &S);
  int cap = 0;
  for (int(i) = 0; (i) < (n); ++(i)) {
    scanf("%d%d%d", &c, &f, &l);
    cap = min(cap + c, 1000000000);
    a[i] = make_pair((l < d), (make_pair((f), (c))));
  }
  sort(a, a + n);
  int idx = -1;
  for (int(i) = 0; (i) < (n); ++(i))
    if (a[i].second.second > 0 && a[i].second.first <= S) {
      if (idx == -1 && !a[i].first) {
        idx = i;
      }
      break;
    }
  int fuel = 0, have = 0;
  if (idx != -1) {
    fuel = a[idx].second.first;
    have = min(cap + 1, n);
  }
  for (int(i) = (0); (i) <= (n - 1); ++(i))
    if (i != idx) {
      if (have == n || a[i].first || fuel + a[i].second.first > S) break;
      ++have, fuel += a[i].second.first;
    }
  pair<int, int> best = make_pair((-have), (fuel));
  fuel = 0, have = 0;
  for (int(i) = (0); (i) <= (n - 1); ++(i))
    if (i != idx) {
      if (have == n || a[i].first || fuel + a[i].second.first > S) break;
      ++have, fuel += a[i].second.first;
    }
  if (make_pair((-have), (fuel)) < best) best = make_pair((-have), (fuel));
  printf("%d %d\n", -best.first, best.second);
  return 0;
}
