#include <bits/stdc++.h>
using namespace std;
const int maxN = 101000;
const int INF = 10010 * 100000;
long long ckol, ccan, minf = INF, cansz, can[maxN];
pair<int, int> solve(long long ted, long long cost, int s, int minf, int n) {
  bool flag = 0;
  for (int i = 0; ted < n && i < cansz; i++) {
    if (can[i] == minf)
      if (!flag) {
        flag = 1;
        continue;
      }
    cost += can[i];
    if (cost > s) {
      cost -= can[i];
      break;
    }
    ted++;
  }
  return make_pair(min<long long>(ted, n), cost);
}
int main() {
  long long n, d, s, t, c, l, f;
  cin >> n >> d >> s;
  t = n;
  for (int i = 0; i < n; i++) {
    cin >> c >> f >> l;
    if (l >= d && f <= s) {
      if (c != 0) minf = min(minf, f);
      can[cansz++] = f;
      ccan += c;
    }
    ckol += c;
  }
  sort(can, can + cansz);
  pair<long long, long long> tc = make_pair(0, 0), tc2;
  if (ccan) {
    tc.first = ckol + 1;
    tc.second = minf;
  }
  tc = solve(tc.first, tc.second, s, minf, n);
  tc2 = solve(0, 0, s, INF, n);
  if (tc.first == tc2.first) tc.second = min(tc.second, tc2.second);
  if (tc2.first > tc.first) {
    tc.first = tc2.first;
    tc.second = tc2.second;
  }
  cout << tc.first << " " << tc.second << endl;
}
