#include <bits/stdc++.h>
using namespace std;
int n, d, s, z;
pair<int, int> r;
vector<int> c0, c1, d0, d1;
int main() {
  scanf("%d%d%d", &n, &d, &s);
  for (int i = 0, ThxDem = n; i < ThxDem; ++i) {
    int c, f, l;
    scanf("%d%d%d", &c, &f, &l);
    z += c;
    if (l >= d) {
      if (!c)
        c0.push_back(f);
      else
        c1.push_back(f);
    } else {
      if (!c)
        d0.push_back(f);
      else
        d1.push_back(f);
    }
  }
  sort(c0.begin(), c0.end());
  sort(c1.begin(), c1.end());
  sort(d0.begin(), d0.end());
  sort(d1.begin(), d1.end());
  int sf = 0, k = 0;
  while (k < ((int)(c0).size()) && sf + c0[k] <= s) sf += c0[k++];
  r = max(r, make_pair(k, -sf));
  if (((int)(c1).size()) && c1[0] <= s) {
    int ss = s;
    s -= c1[0];
    int k = ((int)(c1).size()) + ((int)(d1).size());
    while (k <= z && (((int)(c0).size()) || ((int)(d0).size()))) {
      k++;
      if (((int)(d0).size()))
        d0.pop_back();
      else
        c0.pop_back();
    }
    int t0 = 0, t1 = 1;
    while (t0 < ((int)(c0).size()) ||
           t1 < ((int)(c1).size()) && ((int)(d0).size())) {
      if (t0 < ((int)(c0).size()) &&
          (t1 == ((int)(c1).size()) || c0[t0] < c1[t1])) {
        if (c0[t0] > s) break;
        s -= c0[t0++];
        k++;
      } else {
        assert(t1 < ((int)(c1).size()));
        if (c1[t1] > s) break;
        s -= c1[t1++];
        k++;
        if (((int)(d0).size()))
          d0.pop_back();
        else {
          assert(t0 < ((int)(c0).size()));
          c0.pop_back();
        }
      }
    }
    r = max(r, make_pair(k, s - ss));
  }
  printf("%d %d\n", r.first, -r.second);
  return 0;
}
