#include <bits/stdc++.h>
using namespace std;
int ToInt(string& s, int len) {
  int r = 0;
  for (int i = 0, max_ = (len); i < max_; ++i) {
    r *= 10;
    r += s[i] - '0';
  }
  return r;
}
int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * (b / GCD(a, b)); }
long long Pow(long long n, long long e) {
  if (e == 0) return 1;
  if (e == 1)
    return n;
  else if (e & 1) {
    long long t = Pow(n, e / 2);
    return n * t * t;
  } else {
    long long t = Pow(n, e / 2);
    return t * t;
  }
}
vector<int> moveC;
vector<int> moveOnly;
int main() {
  int N, D, S, c, f, l;
  long long sumC = 0;
  while (scanf("%d %d %d", &N, &D, &S) == 3) {
    sumC = 0;
    moveC.clear();
    moveOnly.clear();
    for (int i = 0, max_ = (N); i < max_; ++i) {
      scanf("%d %d %d", &c, &f, &l);
      sumC += c;
      if (l >= D) {
        if (c > 0)
          moveC.push_back(f);
        else
          moveOnly.push_back(f);
      }
    }
    sort((moveC).begin(), (moveC).end());
    sort((moveOnly).begin(), (moveOnly).end());
    long long res1 = 0, fuel1 = 0;
    if ((int)(moveC).size() > 0 && moveC[0] <= S) {
      res1 = sumC + 1;
      fuel1 += moveC[0];
      int id1 = 1, id2 = 0, f1, f2;
      while (true) {
        f1 = f2 = numeric_limits<int>::max();
        if (id1 < (int)(moveC).size()) f1 = moveC[id1];
        if (id2 < (int)(moveOnly).size()) f2 = moveOnly[id2];
        if (res1 >= N) break;
        if (f1 <= f2) {
          if (S - fuel1 >= f1) {
            ++res1;
            fuel1 += f1;
            ++id1;
          } else
            break;
        } else {
          if (S - fuel1 >= f2) {
            ++res1;
            fuel1 += f2;
            ++id2;
          } else
            break;
        }
      }
      res1 = std::min(res1, (long long)N);
    }
    long long res2 = 0, fuel2 = 0;
    if ((int)(moveOnly).size() > 0) {
      int id = 0;
      while (id < (int)(moveOnly).size() && S - fuel2 >= moveOnly[id]) {
        fuel2 += moveOnly[id];
        ++res2;
        ++id;
      }
    }
    long long res = 0, fuel = 0;
    if (res1 > res2 || (res1 == res2 && fuel1 < fuel2)) {
      res = res1;
      fuel = fuel1;
    } else {
      res = res2;
      fuel = fuel2;
    }
    if (res == 0)
      printf("0 0\n");
    else
      printf("%I64d %I64d\n", res, fuel);
  }
  return 0;
}
