#include <bits/stdc++.h>
using namespace std;
template <class T>
void input(T &x) {
  char c = getchar();
  x = 0;
  for (; (c < 48 || c > 57); c = getchar())
    ;
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
}
inline long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const int N = 1e5 + 5;
int c[N], f[N], l[N];
const long long INF = 1e9 + 9;
long long n, d, s;
long long ans = 0;
long long fuel = INF;
void func1() {
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    if (l[i] >= d) {
      v.push_back(f[i]);
    }
  }
  sort((v).begin(), (v).end());
  fuel = 0;
  for (long long i = 0; i < v.size(); i++) {
    if (fuel + v[i] <= s) {
      fuel += v[i];
      ans++;
    } else
      break;
  }
}
void func2() {
  vector<long long> A, B;
  long long C = 0;
  for (long long i = 0; i < n; i++) {
    if (c[i] > 0) {
      C += c[i];
      if (l[i] >= d) A.push_back(f[i]);
    } else if (l[i] >= d)
      B.push_back(f[i]);
    C = min(C, n);
  }
  sort((A).begin(), (A).end());
  sort((B).begin(), (B).end());
  C = min(C, n);
  if (A.size() == 0) return;
  long long sum = A[0];
  long long L = 1, R = 0;
  long long cnt = L + R + C;
  cnt = min(cnt, n);
  if (sum <= s && (cnt > ans || (cnt == ans && sum < fuel))) {
    ans = cnt;
    fuel = sum;
  }
  while ((L < A.size() || R < B.size()) && sum <= s) {
    long long now = INF;
    if (L < A.size()) now = A[L];
    if (R < B.size()) now = min(now, B[R]);
    if (now == INF) break;
    sum += now;
    if (sum > s) break;
    if (L < A.size() && now == A[L])
      L++;
    else if (R < B.size() && now == B[R])
      R++;
    cnt = L + R + C;
    cnt = min(cnt, n);
    if (cnt > ans || (cnt == ans && sum < fuel)) {
      ans = cnt;
      fuel = sum;
    }
  }
}
int main() {
  cin >> n >> d >> s;
  long long cnt = 0;
  for (long long i = 0; i < n; i++) {
    input(c[i]), input(f[i]), input(l[i]);
  }
  func1();
  func2();
  if (ans > 0)
    cout << ans << " " << fuel << endl;
  else
    printf("0 0\n");
  return 0;
}
