#include <bits/stdc++.h>
using namespace std;
struct robot {
  long long c, f, l;
  bool operator<(const robot &o) const {
    if (l != o.l) return l > o.l;
    return f < o.f;
  }
  robot(long long cc, long long ff, long long ll) {
    c = cc;
    f = ff;
    l = ll;
  }
};
vector<robot> carry;
vector<robot> woCarry;
int main() {
  long long n, d, S;
  cin >> n >> d >> S;
  long long sumC = 0;
  for (int i = 0; i < n; i++) {
    long long c, f, l;
    cin >> c >> f >> l;
    if (l >= d)
      l = 1;
    else
      l = 0;
    sumC += c;
    if (c)
      carry.push_back(robot(c, f, l));
    else
      woCarry.push_back(robot(c, f, l));
  }
  sort(carry.begin(), carry.end());
  sort(woCarry.begin(), woCarry.end());
  long long ans = 0;
  long long rem = S;
  for (int i = 0; i < woCarry.size(); i++) {
    if (woCarry[i].l && woCarry[i].f <= rem) {
      ans++;
      rem -= woCarry[i].f;
    }
  }
  long long use = S - rem;
  long long ans2 = 0;
  rem = S;
  if (carry.size() > 0 && carry[0].f <= S && carry[0].l) {
    ans2 += carry.size();
    rem -= carry[0].f;
    long long carrier = sumC - carry.size() + 1;
    long long id1 = 0, id2 = 1;
    ans2 += min(carrier, (long long)woCarry.size());
    long long ed1 = woCarry.size() - carrier;
    while (id1 < ed1 && id2 < carry.size()) {
      if (!woCarry[id1].l || !carry[id2].l) break;
      if (min(woCarry[id1].f, carry[id2].f) <= rem) {
        if (woCarry[id1].f > carry[id2].f) {
          rem -= carry[id2].f;
          id2++;
          ed1--;
          ans2++;
        } else {
          rem -= woCarry[id1].f;
          id1++;
          ans2++;
        }
      } else
        break;
    }
    while (id1 < ed1 && woCarry[id1].l && woCarry[id1].f <= rem) {
      ans2++;
      rem -= woCarry[id1].f;
      id1++;
    }
    while (id1 < ed1 && id2 < carry.size() && carry[id2].l &&
           carry[id2].f <= rem) {
      ans2++;
      rem -= carry[id2].f;
      id2++;
      id1++;
    }
    if (ans2 > ans) {
      ans = ans2;
      use = S - rem;
    } else if (ans2 == ans) {
      use = min(use, S - rem);
    }
  }
  cout << ans << " " << use << endl;
}
