#include <bits/stdc++.h>
using namespace std;
const long long MX = 111111111;
long long f1[111111], g1[111111], f2[111111], g2[111111], ff1, gg1, ff2, gg2,
    tt, n, d, ss, c, f, l, mc, lmt, tot;
long long s[111111];
void chat(long long hs, long long y) {
  long long x = 0, mid;
  while (x < y) {
    mid = (x + y) / 2;
    if (s[mid + 1] + tot <= ss)
      x = mid + 1;
    else
      y = mid;
  }
  if (hs + x > mc) {
    mc = hs + x;
    lmt = tot + s[x];
  } else if (hs + x == mc) {
    if (lmt > tot + s[x]) lmt = tot + s[x];
  }
}
void check(int tn) {
  long long mlmt, mc, i, j, k, ets, ll;
  k = ff1 + ff2;
  ets = tn + tt - ff1 - ff2;
  if (ets < gg2) {
    k += ets;
    ll = gg1;
  } else {
    ets -= gg2;
    k += gg2;
    if (ets > gg1) {
      ets = gg1;
    }
    k += ets;
    ll = gg1 - ets;
  }
  chat(k, ll);
}
int main() {
  long long i, j;
  while (cin >> n >> d >> ss) {
    tt = 0;
    ff1 = gg1 = ff2 = gg2 = mc = lmt = 0;
    for (i = 0; i < n; i++) {
      cin >> c >> f >> l;
      tt += c;
      if (c == 0) {
        if (l >= d)
          g1[gg1++] = f;
        else
          g2[gg2++] = f;
      } else {
        if (l >= d)
          f1[ff1++] = f;
        else
          f2[ff2++] = f;
      }
    }
    sort(f1, f1 + ff1);
    sort(g1, g1 + gg1);
    sort(f2, f2 + ff2);
    sort(g2, g2 + gg2);
    s[0] = 0;
    for (i = 1; i <= gg1; i++) s[i] = s[i - 1] + g1[i - 1];
    tot = 0;
    chat(0, gg1);
    for (i = 0; i < ff1; i++) {
      tot += f1[i];
      if (tot > ss) break;
      check(i + 1);
    }
    cout << mc << " " << lmt << endl;
  }
  return 0;
}
