#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1001000;
int n, d, S;
int sum = 0;
struct rob {
  int c, l, f;
};
rob r[MAXN];
bool scmp(rob a, rob b) { return a.f < b.f; }
bool czy[MAXN];
int cnnt = 0;
void readData() {
  scanf("%d%d%d", &n, &d, &S);
  for (int i = 0; i < (n); ++i) {
    scanf("%d%d%d", &(r[i].c), &(r[i].f), &(r[i].l));
    sum += r[i].c;
    sum = min(sum, 1001000);
    if (r[i].f == 0 && r[i].l >= d) {
      cnnt++;
    }
  }
  sort(r, r + n, scmp);
}
void check() {
  for (int i = 0; i < (n - 1); ++i) {
    if (r[i].f <= r[i + 1].f) continue;
    printf("jebac!\n");
  }
}
int main() {
  readData();
  int res1 = 0, res2 = 0;
  int fu = S;
  int fir = 0;
  while (fir < n) {
    if (r[fir].c > 0 && r[fir].l >= d && fu >= r[fir].f) {
      fu -= r[fir].f;
      break;
    }
    fir++;
  }
  int kkkk;
  int futt = S;
  int ccc = 0;
  while (ccc < n && futt >= 0) {
    if (r[ccc].l < d) {
      ccc++;
      continue;
    }
    if (futt < r[ccc].f) break;
    res1++;
    futt -= r[ccc].f;
    ccc++;
  }
  kkkk = S - futt;
  if (fir == n || r[fir].f > S) {
    printf("%d %d\n", res1, S - futt);
    return 0;
  }
  fu = S;
  fir = 0;
  while (fir < n) {
    if (r[fir].c > 0 && r[fir].l >= d && fu >= r[fir].f) {
      fu -= r[fir].f;
      res2++;
      czy[fir] = true;
      break;
    }
    fir++;
  }
  for (int i = 0; i < (n); ++i) {
    if (sum + res2 >= n) break;
    if (czy[i]) continue;
    if (r[i].l < d) continue;
    if (fu < r[i].f) break;
    res2++;
    czy[i] = true;
    fu -= r[i].f;
  }
  for (int i = 0; i < (n); ++i) {
    if (czy[i]) continue;
    if (r[i].c == 0) continue;
    sum--;
    res2++;
    czy[i] = true;
  }
  for (int i = 0; i < (n); ++i) {
    if (czy[i]) continue;
    if (sum == 0) break;
    sum--;
    res2++;
    czy[i] = true;
  }
  if (res1 > res2 || (res1 == res2 && S - fu > kkkk)) {
    printf("%d %d\n", res1, kkkk);
  } else {
    printf("%d %d\n", res2, S - fu);
  }
}
