#include <bits/stdc++.h>
using namespace std;
struct Robot {
  int c, f, l;
};
int N, D, S, n1, n2;
Robot a[100005], b[100005];
long long psum[100005];
int compare(Robot r1, Robot r2) {
  if (r1.l < D) return false;
  if (r1.l >= D && r2.l < D) return true;
  return r1.f < r2.f;
}
int main() {
  long long res1 = 0, res2 = 0;
  n1 = n2 = 0;
  scanf("%d %d %d", &N, &D, &S);
  long long numEdges = 0;
  for (int i = 0; i < N; i++) {
    int c, f, l;
    scanf("%d %d %d", &c, &f, &l);
    if (c != 0) {
      a[n1].c = c;
      a[n1].f = f;
      a[n1].l = l;
      n1++;
    } else {
      b[n2].c = c;
      b[n2].f = f;
      b[n2].l = l;
      n2++;
    }
    numEdges += c;
  }
  sort(a, a + n1, compare);
  sort(b, b + n2, compare);
  for (int i = 0; i < n2; i++) {
    if (i == 0)
      psum[i] = b[i].f;
    else
      psum[i] = psum[i - 1] + b[i].f;
  }
  for (int i = 0; i < n2; i++) {
    if (b[i].l < D) {
      n2 = i;
      break;
    }
  }
  long long totalFuel = 0;
  for (int i = 0; i < n1; i++) {
    if (a[i].l < D) break;
    long long maxCarry =
        ((((long long)N) < (numEdges + i + 1)) ? ((long long)N)
                                               : (numEdges + i + 1));
    totalFuel += a[i].f;
    if (totalFuel > (long long)S) break;
    if (maxCarry > res1 || (maxCarry == res1 && totalFuel < res2)) {
      res1 = maxCarry;
      res2 = totalFuel;
    }
    long long sres1 = 0, sres2 = 0;
    int low = 0, high = n2 - 1;
    while (low <= high) {
      int mid = (low + high) / 2;
      long long sum = psum[mid];
      if (sum + totalFuel > (long long)S || maxCarry + mid + 1 > N) {
        high = mid - 1;
      } else {
        sres1 = maxCarry + mid + 1;
        sres2 = sum + totalFuel;
        low = mid + 1;
      }
    }
    if (sres1 > res1 || (sres1 == res1 && sres2 < res2)) {
      res1 = sres1;
      res2 = sres2;
    }
  }
  totalFuel = 0;
  for (int i = 0; i < n2; i++) {
    totalFuel += b[i].f;
    if (totalFuel > (long long)S) break;
    if ((long long)(i + 1) > res1 ||
        ((long long)(i + 1) == res1 && totalFuel < res2)) {
      res1 = i + 1;
      res2 = totalFuel;
    }
  }
  cout << res1 << " " << res2 << endl;
  return 0;
}
