#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e9 + 7;
long long n, s, d, ts, ts2, ans, ans2, tmp, c_sum, mn;
vector<int> cvl, cv;
void input() {
  cin >> n >> d >> s;
  for (int i = 1, c, f, l; i <= n; i++) {
    cin >> c >> f >> l;
    c_sum += c;
    if (l >= d) c ? cvl.push_back(f) : cv.push_back(f);
  }
  ts = ts2 = s;
}
int main() {
  input();
  cvl.push_back(maxn);
  cv.push_back(maxn);
  sort(cvl.begin(), cvl.end());
  sort(cv.begin(), cv.end());
  (cvl.size()) ? mn = cvl[0] : mn = -1;
  for (int f : cv)
    if (ts2 >= f) ans2++, ts2 -= f;
  if (cvl.size() != 1 && s >= mn) {
    ans = min(c_sum + 1, n);
    ts -= mn;
    int pl = 1, p = 0;
    while (ans < n && (tmp = min(cvl[pl], cv[p])) <= ts) {
      ts -= tmp;
      ans++;
      (tmp == cvl[pl]) ? pl++ : p++;
    }
  }
  if (ans2 > ans)
    ans = ans2, ts = ts2;
  else if (ans2 == ans)
    ts = min(ts, ts2);
  cout << ans << ' ' << s - ts << endl;
  return 0;
}
