#include <bits/stdc++.h>
using namespace std;
int random(int k) {
  static int x = time(0);
  x += (x << 2) + (x >> 2) + (x << 4) + (x >> 4) + 1;
  x &= (0x7fffffff);
  return x % k;
}
int f[100010];
void lemon() {
  int n, V, dis;
  scanf("%d%d%d", &n, &dis, &V);
  int cnt = 0;
  long long carry = 1;
  int min = 2000000000, where, have = 0;
  for (int i = (1); i <= (n); i++) {
    int tc, tf, tmp;
    scanf("%d%d%d", &tc, &tf, &tmp);
    if (tmp < dis) tf = 2000000000;
    f[++cnt] = tf;
    if (tc) {
      if (tf < min) min = tf;
      carry += tc - 1;
      have++;
    }
  }
  sort(f + 1, f + cnt + 1);
  if (min != 2000000000) {
    for (int i = (1); i <= (cnt); i++)
      if (f[i] == min) {
        where = i;
        break;
      }
    for (int i = (where + 1); i <= (cnt); i++) f[i - 1] = f[i];
    cnt--;
  }
  if (carry + have > n) carry = n - have;
  int final = 0, fv = 0;
  if (min <= V) {
    int v = V - min, k = 1;
    while (k <= n - have - carry && v >= f[k]) v -= f[k], k++;
    k--;
    int x = k + have + carry;
    if (x > final)
      final = x, fv = v;
    else if (x == final && v > fv)
      fv = v;
  }
  int k = 1, v = V;
  while (k <= cnt && v >= f[k]) v -= f[k], k++;
  k--;
  if (k > final)
    final = k, fv = v;
  else if (k == final && v > fv)
    fv = v;
  printf("%d %d\n", final, V - fv);
}
int main() {
  lemon();
  return 0;
}
