#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18 + 7;
const int N = 1e5 + 7;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1e-9;
struct Node {
  int c, f, l;
  Node() {}
  Node(int _c, int _f, int _l) { c = _c, f = _f, l = _l; }
};
int n, d, S;
vector<Node> vec;
bool cmp(const Node &p, const Node &q) { return p.f < q.f; }
pair<int, int> solve() {
  pair<int, int> ans = make_pair(0, 0);
  int C = 0, flag = 0, minFuel = INF;
  for (int i = (0); i < (n); ++i) {
    int c, f, l;
    scanf("%d%d%d", &c, &f, &l);
    C = min(n, C + c);
    if (l >= d && f <= S) {
      vec.push_back(Node(c, f, l));
      if (c > 0) flag = 1, minFuel = min(minFuel, f);
    }
  }
  C *= flag;
  if (C >= n) ans = make_pair(n, -minFuel), C = 0;
  sort(vec.begin(), vec.end(), cmp);
  if (flag) {
    for (int i = (1); i < (((int)(vec).size())); ++i)
      if (vec[i].f == minFuel) {
        swap(vec[i], vec[0]);
        break;
      }
    sort(vec.begin() + 1, vec.end(), cmp);
  }
  int s = 0;
  for (int i = 0; i < ((int)(vec).size()) && s + vec[i].f <= S && C < n; ++i)
    ++C, s += vec[i].f;
  ans = max(ans, make_pair(C, -s));
  C = s = 0;
  for (int i = 1; i < ((int)(vec).size()) && s + vec[i].f <= S && C < n; ++i)
    ++C, s += vec[i].f;
  ans = max(ans, make_pair(C, -s));
  return ans;
}
int main() {
  scanf("%d%d%d", &n, &d, &S);
  pair<int, int> ans = solve();
  printf("%d %d\n", ans.first, -ans.second);
  return 0;
}
