#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int n, d, s, c, f, l;
  scanf("%d %d %d", &n, &d, &s);
  vector<pair<int, int> > a;
  int m = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &c, &f, &l);
    m = min(n, m + c);
    if (l >= d) a.push_back(make_pair(f, c));
  }
  sort(a.begin(), a.end());
  int r = 0, w = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i].first + w > s) break;
    r++;
    w += a[i].first;
  }
  int k;
  for (k = 0; k < a.size(); k++)
    if (a[k].second != 0) break;
  if (k == a.size() || a[k].first > s) {
    cout << r << ' ' << w << endl;
    return 0;
  }
  pair<int, int> ans = make_pair(r, -w);
  r = 0;
  w = a[k].first;
  ans = max(ans, make_pair(min(m + 1, n), -w));
  for (int i = 0; i < a.size(); i++) {
    if (i == k) continue;
    if (w + a[i].first > s) break;
    r++;
    w += a[i].first;
    ans = max(ans, make_pair(min(n, m + 1 + r), -w));
  }
  cout << ans.first << ' ' << -ans.second << endl;
  return 0;
}
